Get apk file icon, version, name

后端 未结 5 912
粉色の甜心
粉色の甜心 2020-12-04 11:52

Is there a way I can get application name, application version and application icon, for the package that is not yet installed? (for some apk file on sdcard

5条回答
  •  温柔的废话
    2020-12-04 12:26

    // Install a known apk file from the SD-Card
    // or launch it if installed. 
    // -hsigmond
    
    protected void runAppFromApkFileOnSdCard() {
    
            final PackageManager pm = getActivity().getPackageManager();
            String apkFileName      = "application_name.apk";
            String fullPath         = "/sdcard/"+apkFileName;
            PackageInfo packageInfo = pm.getPackageArchiveInfo(fullPath, 0);
            Intent intent           = pm.getLaunchIntentForPackage(packageInfo.packageName);
    
            if( intent == null ){
                File file   = new File(fullPath);
                intent      = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
            }
            startActivity(intent);
        }
    

    Use:

    packageInfo.applicationInfo.['name','icon','logo'] etc.
    

    Example Icon:

    Drawable icon = packageInfo.applicationInfo.loadIcon(getActivity().getPackageManager());
    

提交回复
热议问题