2014-03-12 48 views
1

我開始在Android中開發,並且我試圖瞭解權限,但是我製作的應用程序無法正常工作,即使開啓者應用程序沒有啓用「危險」應用程序所需的權限來打開它。Android沒有足夠的權限打開應用程序

危險清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.second_dangerousapp" 
android:versionCode="1" 
android:versionName="1.0" > 
<permission 
    android:name="com.dangerous_app.permission.DANGEROUS_ACTIVITY" 
    android:label="@string/label_dangerousActivity" 
    android:description="@string/description_dangerousActivity" 
    android:permissionGroup="android.permission-group.APP_INFO" > 
</permission> 

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

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.second_dangerousapp.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.DANGEROUS_ACTIVITY" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

軟件本身是一個簡單的TextView文本。

然後開門紅應用 權限體現

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


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

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

和主要活動

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button btnOpen = (Button) findViewById(R.id.buttonOpen); 
    btnOpen.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent open = new Intent("android.intent.action.DANGEROUS_ACTIVITY"); 
      startActivity(open); 
     } 
    }); 
} 

我在做什麼錯的代碼。因爲現在許可應用程序不應該能夠打開危險的應用程序,因爲它沒有所需的權限。

回答

1

原因現在權限應用程序不應該能夠打開危險的應用程序,因爲它沒有所需的權限。

您沒有使用自定義權限捍衛您應用中的任何內容。只要有一個<permission>元素什麼也不做,除了定義權限。您需要適用某處的權限,例如通過您的<activity>上的android:permission屬性。

您可能還需要閱讀this blog post關於一些與自定義權限有關的意外行爲。

+0

你可以舉個例子。我無法找到任何工作的例子。 – bucur89

+0

找到了答案。 'android:permission =「com.dangerous_app.permission.DANGEROUS_ACTIVITY」' – bucur89

相關問題