我希望从我的应用程序获得另一个应用程序的所有权限

时间:2013-08-13 12:54:11

标签: android permissions

我的申请被强制关闭。请帮我。我想获取应用程序在我的手机中使用的权限列表。

package com.permissions;

import android.os.Bundle;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.widget.TextView;

public class GetPermissions extends Activity {

TextView tvShow;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_permissions);

    tvShow = (TextView) findViewById(R.id.tvshow);
    tvShow.setText(PackageManager.GET_PERMISSIONS);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.get_permissions, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:1)

首先,行tvShow.setText(PackageManager.GET_PERMISSIONS);对您没有帮助。它只获取您在Manifest文件中给出的权限。未在清单文件中声明的requiored权限将显示在LogCat错误中。

如果您想获得应用中使用的权限,那么here中的代码将有所帮助

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);

for (Object obj : pkgAppsList) {
  ResolveInfo resolveInfo = (ResolveInfo) obj;
  PackageInfo packageInfo = null;
  try {
    packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
  } catch (NameNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  String[] requestedPermissions = packageInfo.requestedPermissions;
}