Android获得apk安装包版本和包名等信息


Android #apk #安装2014-04-30 16:46

在APK安装的时候,我们可以获取安装包、版本、包名等信息。

public class test4 extends Activity {    
        
    @Override    
    public void onCreate(Bundle savedInstanceState) {    
        super.onCreate(savedInstanceState);           
        setContentView(R.layout.main);        
        String archiveFilePath="sdcard/download/yige_org.apk";//安装包路径    
        PackageManager pm = getPackageManager();      
        PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);      
        if(info != null){      
            ApplicationInfo appInfo = info.applicationInfo;      
            String appName = pm.getApplicationLabel(appInfo).toString();      
            String packageName = appInfo.packageName;  //得到安装包名称    
            String version=info.versionName;       //得到版本信息         
            Toast.makeText(test4.this, "packageName:"+packageName+";version:"+version, Toast.LENGTH_LONG).show();    
            Drawable icon = pm.getApplicationIcon(appInfo);//得到图标信息    
            TextView tv = (TextView)findViewById(R.id.tv); //显示图标    
            tv.setBackgroundDrawable(icon);    
        }      
    }    
    
}   


相关文章

粤ICP备11097351号-1