Reputation: 1
I am new to android dev and little knowledge of java.I want to know how to inflate a layout from service using SYSTEM_ALERT_WINDOW
public void checkDrawOverlayPermission() {
/* check if we already have
permission to draw over
other apps */
if(android.os.Build.VERSION.SDK_INT > 23) {
if (!Settings.canDrawOverlays(this))
{
/* if not construct intent to request permission */
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
/* request permission via start activity for result */
startActivityForResult(intent, REQUEST_CODE);
}
else {
createOnTopView();
}}}}
I used that to get permission↑↑↑
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/* check if received result code
is equal our requested code for draw permission */
if (requestCode == REQUEST_CODE && android.os.Build.VERSION.SDK_INT > 22) {
/* if so check once again if we have permission */
if (Settings.canDrawOverlays(this)) {
createOnTopView();
}
}
}
after I run this on my phone Teckno k7 ,android 6.0 It runs well buh can't run on my friend's phone Techno F2.it crashes on his phone. Please help me.
Upvotes: 0
Views: 390