最近公司需要做一个快捷功能
打开系统计算器,便签
网上找了很多,发现问题就是不同的手机厂商 计算器包名都不一致
eg:
oppo:com.coloros.calculator
vivo: com.android.bbkcalculator
所以写了一个综合和办法,获取所有的APP 截取包名中包含 calculator:
String calculatorPackage = null; PackageManager pm = mContext.getPackageManager(); // 查询所有已经安装的应用程序 List appInfos= pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的 for (ApplicationInfo applicationInfo : appInfos){ String packageName = applicationInfo.packageName; if (packageName.contains("calculator")){ calculatorPackage = packageName; break; } } Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(calculatorPackage); mContext.startActivity(intent);
同理 便签
String notePackage = null; PackageManager pm = mContext.getPackageManager(); // 查询所有已经安装的应用程序 List appInfos= pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的 for (ApplicationInfo applicationInfo : appInfos){ String packageName = applicationInfo.packageName; if (packageName.contains("note")){ notePackage = packageName; break; } } Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(notePackage); mContext.startActivity(intent);
OK
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)