Click here to Skip to main content
14,091,993 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

22.7K views
3 bookmarked
Posted 17 Nov 2015
Licenced CPOL

Android Marshmallow Overlay Permission

, 17 Nov 2015
Rate this:
Please Sign up or sign in to vote.
System overlay permissions in Android M

Introduction

This tip explains some intricacies around system overlay permissions introduced in Android M.

Background

Android has allowed applications to draw over all other applications using the SYSTEM_ALERT_WINDOW permission. This was allowed as long as the permission was declared in the manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >
...
    </application>
...
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

</manifest>

This technique was used by several applications that required drawing over other apps. A good example is the Facebook chatheads that float over other apps.

What Happened in M?

In Android M, the SYSTEM_ALERT_WINDOW permission was categorized as a 'dangerous' permission. This is understandable because you can imagine a transparent application intercepting your touches or inputs. So, instead of allowing the applications to use the overlay with just the manifest declaration, in Android M, the user needs to provide specific permission in Android settings for the app to draw over other apps.

This setting could be found in Settings -> Apps -> Advanced (settings icon) -> Draw over other apps

As you may be aware, Android M did introduce fine grained application permissions that the application can request for. But, as this is classified as a dangerous permission, applications cannot request this permission to the user specifically.

Solution

One possible solution is to direct the user to the above screen if the user is running Android M or above. Fortunately, Android does provide a ready made intent action that you could use to launch the above Activity.

Code:

// Check if Android M or higher
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
    // Show alert dialog to the user saying a separate permission is needed
    // Launch the settings activity if the user prefers
    Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
    startActivity(myIntent);
}

That's it. The action ACTION_MANAGE_OVERLAY_PERMISSION directly launches the 'Draw over other apps' permission screen.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sreenivas Satish
Technical Lead
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

 
SuggestionMissing Image Pin
Abhishek Pant17-Nov-15 18:10
professionalAbhishek Pant17-Nov-15 18:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190518.1 | Last Updated 17 Nov 2015
Article Copyright 2015 by Sreenivas Satish
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid