Problem with permission to run an activity
I`m trying to understand, how permissions wo开发者_Python百科rk in android. I made simple project: 1 source file and 1 xml-layout. And:
1) I define permission to activity (activity name is "AndroidTestActivity", permission name is "android.permission.MY_PERMISSION"),
2) I define uses-permission for activity (), My problem is: when I run AndroidTestActivity, 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:
public class AndroidTestActivity extends Activity {
TextView tv;
Menu myMenu=null;
@Override
public void onCreate(Bundle savedlnstanceState) {
super.onCreate(savedlnstanceState);
setContentView(R.layout.main);
}
}
According to the docs it should smth like this:
<permission android:name="com.example.Android.Test.permission.MY_PERMISSION"
android:protectionLevel="normal"
android:description="Some description"
android:label="Some label" />
<uses-permission
android:name="com.example.Android.Test.permission.MY_PERMISSION" />
精彩评论