返回首頁
當前位置: 主頁 > 網絡編程 > Android教程 >

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

時間:2012-05-11 11:22來源:知行網www.f1globe.com 編輯:麥田守望者

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);
}
}


}

------分隔線----------------------------
標簽(Tag):Android android教程 android技巧 android軟件
------分隔線----------------------------
推薦內容
猜你感興趣
99久久免费高清热精品