如何为每个应用获取应用的权限详细信息?如何以编程方式进行?
我想在TextView上显示“应用程序的每个应用程序的权限详细信息”。 但我试试但不行吗?
Hello.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.content.Intent;
import android.content.Context;
import android.content.pm.*;
import android.widget.TextView;
import java.util.*;
public class HelloSakez extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final ListView lw = (ListView) findViewById(R.id.listView1);
final List<ResolveInfo> pkglist = lw.getContext().getPackageManager().queryIntentActivities(mainIntent, 0);
final TextView tw = (TextView) findViewById(R.id.textView1);
Iterator it = pkglist.iterator();
while(it.hasNext()){
ResolveInfo rf = (ResolveInfo)it.next();
tw.append(rf.toString());
}
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<ListView android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_width="fill_parent"></ListView>
<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
答案 0 :(得分:14)
我创建了StringBuffer appNameAndPermissions = new StringBuffer();
以附加所有应用和权限信息。
工作正常。我已经测试过了。如果您有任何问题,请告诉我。
StringBuffer appNameAndPermissions = new StringBuffer();
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
try {
PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
appNameAndPermissions.append(packageInfo.packageName+"*******:\n");
//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;
if(requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
Log.d("test", requestedPermissions[i]);
appNameAndPermissions.append(requestedPermissions[i]+"\n");
}
appNameAndPermissions.append("\n");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
<uses-permission android:name="android.permission.GET_TASKS"/>
答案 1 :(得分:4)
您需要使用PackageManager的GET_PERMISSIONS标志。
答案 2 :(得分:0)
Zhocker
要卸载任何应用程序,请使用以下代码
Intent i = new Intent(Intent.ACTION_DELETE);
i.setData(Uri.parse("package:com.package name"));
startActivity(i);
要获得权限,请使用带有getInstalledPackages(int)
标志的GET_PERMISSIONS答案 3 :(得分:-3)
2.对于卸载应用程序,请遵循以下几点: -
一个。转到设置 湾然后打开应用程序 C。然后打开管理应用程序 d。然后选择要卸载的应用 即然后单击卸载并卸载应用程序。