从广播接收器启动另一个应用程序
我试图在设备启动后从接收器启动一个活动:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(intent);
当我从我的活动中调用它时,此代码工作正常,但是当我的 BroadcastReceiver 在启动后执行它时,它会失败。我的 Logcat 显示:
ActivityNotFoundException: Have you declared the activity in your AndroidManifest.xml?
任何指点都将不胜感激。提前致谢。
I am trying to start an activity from a Receiver after the device boot:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(intent);
This code just works fine when I call it from my activity however it fails when my BroadcastReceiver executes it after bootup. My Logcat shows:
ActivityNotFoundException: Have you declared the activity in your AndroidManifest.xml?
Any pointers will be greatly appreciated. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为只需要这 3 行,上下文将是您在广播接收器中收到的上下文。
i think this 3 lines only needed and the context will be the context u receive in broadcast receiver.
当您在清单中声明 Activity 时,您可能拼写或犯了错误。确保你把它放在那里并且拼写正确
You probably spelled or made a error when you declared your Activity in your manifest. Make sure you put it in there and spelled everything correctly
我认为问题出在以下行中。您的活动的名称是什么?是“ActivityName”吗?还要检查包名称。
I think the problem is in the following Line.what is the name of your Activity?is it "ActivityName"?Also Check package name.