我有一个库项目和主项目,我尝试从主项目启动库项目中定义的活动。
Intent intent = new Intent("isr.LAUNCH");
intent.setComponent(new ComponentName("com.ISR", "com.ISR.activity.CameraActivity"));
startActivity(intent);
但我收到以下异常:
05-14 17:13:42.853: E/AndroidRuntime(29217): java.lang.SecurityException: Permission Denial: starting Intent { act=isr.LAUNCH cmp=com.ISR/.activity.CameraActivity } from ProcessRecord{40aa7178 29217:com.ssbs.sw.SWE/10094} (pid=29217, uid=10094) requires null
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Parcel.readException(Parcel.java:1322)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Parcel.readException(Parcel.java:1276)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Activity.startActivityForResult(Activity.java:2827)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.Activity.startActivity(Activity.java:2933)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.ssbs.sw.IR.view.MainActivity$1$1.onMenuItemClick(MainActivity.java:58)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.ssbs.sw.SWE.actionbarV5.menu.MenuButtonHelper$1.onClick(MenuButtonHelper.java:108)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.view.View.performClick(View.java:2492)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.view.View$PerformClick.run(View.java:9087)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Handler.handleCallback(Handler.java:587)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.os.Looper.loop(Looper.java:130)
05-14 17:13:42.853: E/AndroidRuntime(29217): at android.app.ActivityThread.main(ActivityThread.java:3740)
05-14 17:13:42.853: E/AndroidRuntime(29217): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 17:13:42.853: E/AndroidRuntime(29217): at java.lang.reflect.Method.invoke(Method.java:507)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
05-14 17:13:42.853: E/AndroidRuntime(29217): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
05-14 17:13:42.853: E/AndroidRuntime(29217): at dalvik.system.NativeStart.main(Native Method)
这是我来自图书馆项目的清单:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name=".activity.CameraActivity" android:exported="true" >
<intent-filter>
<action android:name="isr.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
我怎样才能解决这个问题?
编辑
我的主要项目清单权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
编辑 2
我通过处理调用活动的主要应用程序清单定义解决了我的问题(但我想知道是否可以在不添加此定义的情况下执行此操作):
<activity android:name="com.ISR.activity.CameraActivity">
<intent-filter>
<action android:name="isr.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
现在我可以使用以下代码开始我的活动:
Intent intent = new Intent("isr.LAUNCH");
startActivity(intent);