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

前端 未结 2 1567
独厮守ぢ
独厮守ぢ 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 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)); 
    }
    

提交回复
热议问题