I want to list permissions taken by an every app installed on device in group wise manner.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Please see this, i hope this will help you.
private static final int REQUEST_PERMISSIONS = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >=23)
{
getPermission();
}
else
{
initView();
}
}
private void initView()
{
setContentView(R.layout.activity_main);
...
..
}
@TargetApi(Build.VERSION_CODES.M)
private void getPermission()
{
if (ContextCompat.checkSelfPermission(StartActivity.this, Manifest.permission.CAMERA)
+ ContextCompat.checkSelfPermission(StartActivity.this, Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
Log.i("Permission is require first time", "...OK...getPermission() method!..if");
ActivityCompat.requestPermissions(StartActivity.this,
new String[]{Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO},
REQUEST_PERMISSIONS);
}
else
{
initView();
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSIONS) {
if ((grantResults.length > 0) && (grantResults[0]+grantResults[1])
== PackageManager.PERMISSION_GRANTED) {
// Permission granted.
initView();
} else {
Toast.makeText(StartActivity.this, "All Permission is Required, Toast.LENGTH_LONG).show();
getPermission()
}
}
}
回答2:
You may be able to retrieve the permissions of your app by using PackageManager. See: list of apps permissions