1

所以我对android编程有点陌生,我真的不知道为什么当我在活动下有一个权限标签时我不能运行主要活动。这是我在清单文件下的代码:

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

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.example.DANGEROUS_ACTION" />

<permission
    android:name="com.example.DANGEROUS_ACTION"
    android:label="permission"
    android:protectionLevel="dangerous" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.lab08b_awahla.MainActivity"
        android:label="@string/app_name"
        android:permission="com.example.DANGEROUS_ACTION" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.example.DANGEROUS_ACTION" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>
4

2 回答 2

3

这是显而易见的。如果您要为活动提供安全标签,任何想要启动此活动的人都必须拥有这样的权限。主屏幕应用程序没有(甚至不知道)您的权限标签,所以这是一个问题。

于 2013-04-07T22:21:59.230 回答
1

根据标签的文档<activity>

android:permission
The name of a permission that clients must have to launch the activity or otherwise get it to respond to an intent. If a caller of startActivity() or startActivityForResult() has not been granted the specified permission, its intent will not be delivered to the activity.

This leads me to think that you misunderstand the use of this attribute.

于 2013-04-07T22:27:32.980 回答