PDA

View Full Version : Problem with permission to run an activity



Evg64
08-19-2011, 03:58 PM
Hello everyone! I`m trying to understand, how permissions work in android. I made simple project for that. My problem is:
1) I define permission to my activity (activity name is "AndroidTestActivity", permission name is "android.permission.MY_PERMISSION"),
2) I define uses-permission for my activity (<uses-permission android:name="android.permission.MY_PERMISSION"></uses-permission>),
3) When I run AndroidTestActivity, my logcat says:

08-19 19:39:18.311: WARN/ActivityManager(59): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.Android.Test/.AndroidTestActivity } from null (pid=-1, uid=-1) requires android.permission.MY_PERMISSION

Why do I get Permission Denial? I made uses-permission, isn`t it enough?
Here is AndroidManifest source:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Android.Test" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<permission android:name="android.permission.MY_PERMISSION" android:protectionLevel="normal"></permission>
<uses-permission android:name="android.permission.MY_PERMISSION"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidTestActivity" android:permission="android.permission.MY_PERMISSION"
android:label="Sample menus application">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is AndroidTestActivity source:

package com.example.Android.Test;

import android.app.Activity;

public class AndroidTestActivity extends Activity {
TextView tv;
Menu myMenu=null;
@Override
public void onCreate(Bundle savedlnstanceState) {
super.onCreate(savedlnstanceState);
setContentView(R.layout.main);
}
}

alostpacket
08-29-2011, 11:01 PM
uses-permission should come after the closing /application tag but before the closing /manifest tag