【发布时间】:2016-07-15 09:21:26
【问题描述】:
我发现几乎相同的问题:How to start an Intent if context is not Activity Context but Application Context
但我在使用https://stackoverflow.com/a/9238105/6593395时没有做到这一点
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("android.intent.action.BOOT_COMPLETED".equals(action)) {
Intent applicationIntent = new Intent(context, myCamApplication.class);
applicationIntent.setAction(myCamApplication.class.getName());
applicationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(applicationIntent);
错误日志:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.fenchtose.asyncamera/com.eason.mycamera.myCamApplication}; have you declared this activity in your AndroidManifest.xml?
我已将此 myCamApplication 类注册为我在 AndroidManifest.xml 中的应用程序类
<application
android:name=".myCamApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<receiver
android:name=".BootComplete"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name=".myCam"
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>
那么,有人可以帮忙吗?
【问题讨论】:
-
你能包含你的代码吗?这样会更容易帮助你
-
您是否在 AndroidManifest.xml 中声明了此活动?
-
@Christopher 是的,我已经包含了 AndroidManifest.xml
-
@Marat 请看一下,谢谢
-
新意图(上下文,myCamApplication.class);错了,这里需要提供Activity类
标签: android android-intent android-context