Reputation: 241
I have read and checked how to do this online and on books but it won't work on my Note 3. This is what I did.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hardkore.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<permission
android:name="com.hardkore.permissions.MY_PERMISSION"
android:protectionLevel="dangerous"
android:label="@string/perm_label"
android:description="@string/perm_desc" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:permission="com.hardkore.permissions.MY_PERMISSION"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.hardkore.permissions.MY_PERMISSION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
this is the error that logcat displayed
02-15 16:21:32.525: W/ActivityManager(807): mDVFSHelper.acquire()
02-15 16:21:32.525: W/ActivityManager(807): Permission Denial: starting Intent {
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.hardkore.testapp/.MainActivity
}
from null (pid=28305, uid=2000) requires com.hardkore.permissions.MY_PERMISSION
02-15 16:21:35.525: W/ActivityManager(807): mDVFSHelper.release()
Upvotes: 3
Views: 6551
Reputation: 1334
try calling the activity like
Intent intent = new Intent();
intent .setAction("com.hardkore.permissions.MY_PERMISSION");
intent .addCategory("android.intent.category.DEFAULT");
startActivity(intent );
And don't forget to add the permission in your other app like
<uses-permission android:name="com.hardkore.permissions.MY_PERMISSION"/>
Upvotes: 0
Reputation: 62519
Your putting a custom permission on your main launcher activity ...How can android start this activity now ? Remove the custom permission or make another main activity.
Upvotes: 0
Reputation: 1876
you should avoid defining a custom permission for your MAIN activity. The android framework is not having that permission and as a result, it won't be able to execute it.
Upvotes: 0
Reputation: 793
After declaring a custom permission in the manifest file, you should also declare that your application is using this permission. This seems redundant, but it worked for me.
<permission
android:name="com.hardkore.permissions.MY_PERMISSION"
android:protectionLevel="dangerous"
android:label="@string/perm_label"
android:description="@string/perm_desc" />
<uses-permission android:name="com.hardkore.permissions.MY_PERMISSION"/>
Upvotes: 3