一、applicationId 与包名
见 https://blog.csdn.net/jinrall/article/details/53465403
总结来说 applicationId 与包名 在默认情况下是相同的。但是可以在moudle层的build.gradle中定义applicationId。
而 this.getApplicationContext()..getPackageName() 、android.app.ActivityThread.currentPackageName得到的都是applicationId。
public void getPackages() { int flag = PackageManager.MATCH_UNINSTALLED_PACKAGES; PackageManager packageManager = getPackageManager(); List<PackageInfo> installedPackages = packageManager.getInstalledPackages(flag); for (PackageInfo installedPackage : installedPackages) { Log.d(TAG, "packagename = " + installedPackage.packageName); } } public void getApplications() { int flag = PackageManager.MATCH_UNINSTALLED_PACKAGES; PackageManager packageManager = getPackageManager(); List<ApplicationInfo> listApplications = packageManager.getInstalledApplications(flag); Collections.sort(listApplications, new ApplicationInfo.DisplayNameComparator(packageManager)); for (ApplicationInfo info : listApplications) { Log.i(TAG, "packagename = " + info.packageName); } }
如上获取安装到手机上所有应用包名其实也是applicationId。
二、判断应用是否为debuggable
见 https://www.cnblogs.com/zhujiabin/p/6874508.html
最优的方法是通过 context.getApplicationInfo().flags & ApplicationInfo.FLAGE_DEBUGGABLE != 0 来判断是否为 debuggable
其中ApplicationInfo.FLAGE_DEBUGGABLE 值为2 (0x00000002), 即flags里的第二位表示应用的debuggable
参见:https://developer.android.com/reference/android/content/pm/ApplicationInfo