The app I am developing requires that I get the package name using PackageManager.
I am able to get the App Icon and and App Name but how do I get the packagename in a way similar to what I have below?
Drawable appIcon = packageManager
.getApplicationIcon(packageInfo.applicationInfo);
String appName = packageManager.getApplicationLabel(
packageInfo.applicationInfo).toString();
我发现这是
PACKAGE_NAME = packageInfo.packageName;
private ArrayList results = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(intent,
PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo.packageName);
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
}
This gives list of all package names installed in your device.
rInfo.activityInfo.applicationInfo.loadLabel(pm)
.toString();
This gives u the app names.
rInfo.loadIcon(getPackageManager());
And this gives the appicon.
String package_name= getPackageManager().getPackageInfo(getPackageName(), 0).packageName;
要么
String package_name= MyContext.getPackageName();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.