1.判斷手機中是否安裝了某個App
/**
* 判斷是否存在某個app
*
* @param context 上下文
* @param packageName 包名
* @return 是否存在
*/
public static boolean checkApkExist(Context context, String packageName) {
if (TextUtils.isEmpty(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
2.獲取App VersionName
/**
* 獲取versionName
*
* @param context 上下文
* @return int值
*/
public static String packageCode(Context context) {
String versionCode = null;
try {
//獲取軟件版本號愁溜,對應(yīng)AndroidManifest.xml下android:versionCode
versionCode = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionCode;
}
3.App狀態(tài)欄透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//status bar is translucent
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
4.當(dāng)前App跳轉(zhuǎn)到另一個app
- 使用這個方法的時候需要在目標(biāo)Activity的清單文件中添加兩行代碼
- 這兩行代碼添加在目標(biāo)App中的目標(biāo)Activity上
android:exported="true"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.panasonic.ACCsmart", "com.panasonic.ACCsmart.ui.login.LoginActivity");
bundle.putString("userId", "test123");
bundle.putString("password", "qwe123");
intent.putExtras(bundle);
intent.setComponent(componentName);
startActivity(intent);