How to get the package name of an application and then launch that app using Intent?

前端 未结 2 1566
独厮守ぢ
独厮守ぢ 2021-01-07 12:41

I am developing an Android app. In that app, there is a button to go to another activity which contains a list of installed apps on the phone. When the user selects an app,

相关标签:
2条回答
  • 2021-01-07 13:08

    Here is the code:

    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for (ApplicationInfo packageInfo : packages) {
        Log.d(TAG, "Installed package :" + packageInfo.packageName);
        Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
    }
    
    0 讨论(0)
  • 2021-01-07 13:10

    the list of installed apps on the phone using PackageManager as show below.

    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for (ApplicationInfo packageInfo : packages) {
        Log.d(TAG, "Installed package :" + packageInfo.packageName);
        Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
    }
    // the getLaunchIntentForPackage returns an intent that you can use with startActivity() 
    

    You will get all the necessary data in the ResolveInfo to start a application. link

    launch app using Intent

    0 讨论(0)
提交回复
热议问题