Everyone should be carefully when the environment is configured. Students could code Android application when the code environment was configured and the environment parameters were setted up.
It is difficulty that students find out the function of corresponding features and obtain the permissions information of application by using function. More preparation and more accumulation are required, otherwise it will spend a lot of time to be familiar with Android program and function etc.. However, students could use the previous accumulation and surf on the CSDN and PUDN technology website to search the relevant technical information. The former could give us well guidance and help.
The source code of the APK file of the experimental release:
>();
PackageManager pm = this.getPackageManager();
List applicationInfos = pm.getInstalledApplications(PackageManager.GET_ACTIVITIES);
HashMap resultMap = new HashMap();
Iterator iterator = applicationInfos.iterator();
while (iterator.hasNext()) {
ApplicationInfo applicationInfo = iterator.next();
HashMap map = new HashMap();
map.put("APP_CLASS_NAME",
applicationInfo.packageName);// APP包名
map.put("APP_NAME", pm.getApplicationLabel(applicationInfo).toString());
listItem.add(map);
}
// 生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,// 数据源
R.layout.listview,// ListItem的XML实现
// 动态数组与ImageItem对应的子项
new String[]{"APP_NAME"},
// ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[]{R.id.APP_NAME});
// 添加并且显示
list.setAdapter(listItemAdapter);
// 添加点击
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
getPermisson(MyActivity.this, inflater, lin,
listItem.get(arg2).get("APP_CLASS_NAME"));
}
});
}
private void getPermisson(Context context, LayoutInflater inflater,
LinearLayout lin, String pkgName) {
setContentView(R.layout.info);
TextView tv = (TextView) findViewById(R.id.TextView_info);
Button bt = (Button) findViewById(R.id.Button1);
bt.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View view) {
setContentView(R.layout.activity_main);
// 绑定Layout里面的ListView
ListView list = (ListView) findViewById(R.id.ListView01);
final LayoutInflater inflater = LayoutInflater.from(MyActivity.this);
final LinearLayout lin = (LinearLayout) findViewById(R.id.Layout01);
listItem = new ArrayList>();
PackageManager pm = MyActivity.this.getPackageManager();
List applicationInfos = pm.getInstalledApplications(PackageManager.GET_ACTIVITIES);
HashMap resultMap = new HashMap();
Iterator iterator = applicationInfos.iterator();
while (iterator.hasNext()) {
ApplicationInfo applicationInfo = iterator.next();
HashMap map = new HashMap();
map.put("APP_CLASS_NAME",
applicationInfo.packageName);// APP包名
map.put("APP_NAME", pm.getApplicationLabel(applicationInfo).toString());
listItem.add(map);
}
// 生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdapter = new SimpleAdapter(MyActivity.this, listItem,// 数据源
R.layout.listview,// ListItem的XML实现
// 动态数组与ImageItem对应的子项
new String[]{"APP_NAME"},
// ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[]{R.id.APP_NAME});
// 添加并且显示
list.setAdapter(listItemAdapter);
// 添加点击
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
getPermisson(MyActivity.this, inflater, lin,
listItem.get(arg2).get("APP_CLASS_NAME"));
}
});
}
});
try {
PackageManager pm = context.getPackageManager();
// PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
PermissionGroupInfo pgi;
PackageInfo pkgInfo = pm.getPackageInfo(pkgName,
PackageManager.GET_PERMISSIONS);
String sharedPkgList[] = pkgInfo.requestedPermissions;
for (int i = 0; i < sharedPkgList.length; i++) {
String permName = sharedPkgList[i];
PermissionInfo tmpPermInfo = pm.getPermissionInfo(permName, 0);
tv.append(i + "-" + permName + "\n");
pgi = pm.getPermissionGroupInfo(tmpPermInfo.group, 0);
tv.append(i + "-" + pgi.loadLabel(pm).toString() + "\n");
tv.append(i + "-" + tmpPermInfo.loadLabel(pm).toString() + "\n");
tv.append(i + "-" + tmpPermInfo.loadDescription(pm).toString()
+ "\n");
tv.append("-------------------------------------------" + "\n");
}
} catch (NameNotFoundException e) {
Log.e("##ddd", "Could'nt retrieve permissions for package");
}
}
}
Share with your friends: