所以我的主要问题是启动一个隐含意图的新应用。所以这是应该启动nem应用程序的活动:
package course.labs.permissionslab;
public class GoToDangerousActivity extends Activity {
private static final String TAG = "Lab-Permissions";
private static final String DANGEROUS_ACTIVITY_ACTION = "course.labs.permissions.DANGEROUS_ACTIVITY_PERM";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.go_to_dangerous_activity);
Button startDangerousActivityButton = (Button) findViewById(R.id.start_dangerous_activity_button);
startDangerousActivityButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startDangerousActivity();
}
});
}
private void startDangerousActivity() {
Log.i(TAG, "Entered startDangerousActivity()");
Intent dangerActivation = Intent.createChooser(new Intent(DANGEROUS_ACTIVITY_ACTION), "Choose yo..");
startActivity(dangerActivation);
}
}
我刚刚添加了appChoser,所以我的应用程序不会立即中断。 现在通过strting隐含的意图“course.labs.permissions.DANGEROUS_ACTIVITY_PERM”,我需要添加到其他应用程序意图过滤器?我将留下其他应用程序Manifest.XML的副本来帮助发现问题:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.labs.dangerousapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<!--
TODO - Using a permission element,
define a custom permission with name
"course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
and "dangerous" protection level.
-->
<permission
android:protectionLevel="dangerous"
android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM">
</permission>
<uses-permission android:name="course.labs.permissions.DANGEROUS_ACTIVITY"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- TODO - enforce the custom permission on this Activity -->
<activity
android:name=".DangerousActivity"
android:label="@string/app_name">
<!--
TODO - add additional intent filter info so that this Activity
will respond to an Implicit Intent with the action
"course.labs.permissions.DANGEROUS_ACTIVITY"
-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:3)
首先,
<uses-permission android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"/>
这应该在您要访问此应用的应用中。
假设你有应用A并想要打开Dangerous App,你可以将此权限用于A的清单文件中。
第二名:
您还需要告知应用程序有关权限。将此权限添加到应用程序。
<application
android:permission="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
<!-- your other attributes -->
>
第三:
Intent过滤器应该链接到Activity而不是权限字符串。
<intent-filter>
<action android:name="course.labs.permissions.DANGEROUS_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>