天梯

道可道非常道

Android获取apk的版本及包名等信息

import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class test4 extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
        setContentView(R.layout.main);    
        String archiveFilePath="sdcard/download/Law.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);
        }  
    }
    
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tyxkzzf/article/details/46831175
文章标签: android 游戏
个人分类: AndroidDevelopment
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭