Search code examples
androidpermission-deniedandroid-permissions

"Permission dinied" for a simple app on Android 5.0


I have an app contains just one Activity and the next Manifest-file below. When I start it on an emulator (android 4.3) it works fine, Activity gets open, but I faced with error "Permission denied" trying to launch the app on my Nexus 5 with Android 5.0. I'v also tried to build it with Sdk version 21, but it didn't help.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="course.labs.dangerousapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="18" />

    <!--
          TODO - Using a permission element,
          define a custom permission with name
              "course.labs.permissions.DANGEROUS_ACTIVITY_PERM" 
          and "dangerous" protection level.
    -->
    <permission
        android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
        android:protectionLevel="dangerous">
    </permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:permission = "course.labs.permissions.DANGEROUS_ACTIVITY_PERM" >

        <!-- TODO - enforce the custom permission on this Activity -->

        <activity
            android:name=".DangerousActivity"
            android:label="@string/app_name" >
            <!--
                 TODO - add additional intent filter info so that this Activity
                  will respond to an Implicit Intent with the action
                  "course.labs.permissions.DANGEROUS_ACTIVITY"
            -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="course.labs.permissions.DANGEROUS_ACTIVITY"/>
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Solution

  • Remove android:permission = "course.labs.permissions.DANGEROUS_ACTIVITY_PERM" from the <application> element.

    First, this probably is supposed to go on an <activity>, given the permission name.

    Second, the behavior of having android:permission on an <application> is generally undocumented. My guess is that it applies the permission to all components inside the application.

    Third, nothing on the device, except perhaps another app that you wrote, will have a <uses-permission> element for this permission. Only such an app would be able to work with your app.