The XML spec for <permission>
and <permission-group>
refers to an icon which you see in Settings | App info | Permissions.
If I already have the permission an app needs in the from of a string from querying the PackageInfo, for example "android.permission.INTERNET", how can I get the associated permission and permission-group icon?
On your phone, open the Settings app. Permission manager. Tap a permission type. If you allowed or denied permission to any apps, you'll find them here.
To check if the user has already granted your app a particular permission, pass that permission into the ContextCompat. checkSelfPermission() method. This method returns either PERMISSION_GRANTED or PERMISSION_DENIED , depending on whether your app has the permission.
The short answer is, you can't. As android documentation puts: When your app calls requestPermissions(), the system shows a standard dialog box to the user. Your app cannot configure or alter that dialog box.
Here is my code.
package sample.com.sample_android;
import android.Manifest;
import android.content.pm.PackageManager;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private static final String ANDROID = "android";
private PackageManager mPackageManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPackageManager = getPackageManager();
String permission = Manifest.permission.INTERNET;
Drawable drawable = getPermissionDrawable(permission);
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageDrawable(drawable);
TextView textView = (TextView) findViewById(R.id.text);
textView.setText(permission);
}
@Nullable
private Drawable getPermissionDrawable(String permission) {
Drawable drawable = null;
try {
PermissionInfo permissionInfo = mPackageManager.getPermissionInfo(permission, 0);
PermissionGroupInfo groupInfo = mPackageManager.getPermissionGroupInfo(permissionInfo.group, 0);
drawable = mPackageManager.getResourcesForApplication(ANDROID).getDrawable(groupInfo.icon);
} catch (PackageManager.NameNotFoundException|Resources.NotFoundException e) {
}
return drawable;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With