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 {
//获取软件版本号,对应AndroidManifest.xml下android:versionCode
versionCode = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionCode;
}
3.App状态栏透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//status bar is translucent
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
4.当前App跳转到另一个app
- 使用这个方法的时候需要在目标Activity的清单文件中添加两行代码
- 这两行代码添加在目标App中的目标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);