WEB开发网
开发学院手机开发Android 开发 Android 获取手机所有应用包名以及权限 阅读

Android 获取手机所有应用包名以及权限

 2012-07-19 14:20:05 来源:WEB开发网   
核心提示: package gongzibai.co.cc;import java.util.List;import android.app.Activity;import android.app.Application;import android.content.pm.ApplicationInfo;import andro

 package gongzibai.co.cc;
import java.util.List;
import android.app.Activity;
import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.Bundle;
import android.widget.TextView;
public class Package1Activity extends
Activity {
TextView mTextView;
/** Called when the activity is first created. */
@Override
public void onCreate(
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView = (TextView) findViewById(R.id.textView1);
PackageManager packageManager = getPackageManager();
List<PackageInfo> list = packageManager
.getInstalledPackages(PackageManager.GET_PERMISSIONS);
StringBuilder stringBuilder = new StringBuilder();
for (PackageInfo packageInfo : list) {
stringBuilder
.append("package name:"
+ packageInfo.packageName
+ "\n");
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
stringBuilder
.append("应用名称:"
+ applicationInfo
.loadLabel(packageManager)
+ "\n");
if (packageInfo.permissions != null) {
for (PermissionInfo p : packageInfo.permissions) {
stringBuilder
.append("权限包括:"
+ p.name
+ "\n");
}
}
stringBuilder.append("\n");
}
mTextView.setText(stringBuilder
.toString());
}
}

Tags:Android 获取 手机

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接