gpt4 book ai didi

android - 如何为应用程序上下文启动 Intent

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:21 24 4
gpt4 key购买 nike

我发现了几乎相同的问题: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?

我已经在 AndroidManifest.xml 中将这个 myCamApplication 类注册为我的应用程序类

    <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>

那么,有人可以帮忙吗?

最佳答案

您不能启动应用程序类。您只能启动一个 Activity 。

更改您的代码,例如:

Intent applicationIntent = new Intent(context, myCamApplication.class);

Intent applicationIntent = new Intent(context, myCam.class);

关于android - 如何为应用程序上下文启动 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38392428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com