首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActivityNotFoundException不解析

ActivityNotFoundException不解析
EN

Stack Overflow用户
提问于 2015-03-29 23:28:35
回答 2查看 361关注 0票数 0

我想通过广播接收器打开活动,我尝试了任何方法,但是我得到了ActivityNotFoundException,我的活动是在正常模式下工作的,但是当我想从BroadCastRecevier打开它时,它会导致ActivityNotFoundException错误,

这是我的名单,

代码语言:javascript
复制
<activity
    android:excludeFromRecents="true" 
    android:launchMode="singleTask"
    android:screenOrientation="portrait"
    android:name="com.alexis.abc.ui.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

这是我的广播接收器

代码语言:javascript
复制
Intent intent2 = new Intent(context, MainActivity.class);
intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setAction("android.intent.action.MAIN");
context.startActivity(intent2);

以下是步骤:

1-i通过以下代码打开应用程序并隐藏启动程序图标

代码语言:javascript
复制
PackageManager packageManager = getContext().getPackageManager();
ComponentName componentName = new ComponentName(getContext(), MainActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

2-我退出应用程序并拨打一个号码(触发广播事件),然后得到以下异常

代码语言:javascript
复制
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.alexis.abc/com.alexis.abc.ui.MainActivity}; have you declared this activity in your AndroidManifest.xml?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-30 00:04:08

你有这样的许可吗?

代码语言:javascript
复制
<receiver
android:name="Your receiver"
android:enabled="true"
android:exported="false" >
   <intent-filter>
       <action android:name="action"/>
       <category android:name="category" />
   </intent-filter>
</receiver>

在你的Android宣言文件里?如果没有,那么试着打开你的Android文件,并将类似于我在上面发布的内容放在上面。

或者在代码的最后一行尝试.sendBroadcast()而不是.startActivity():

代码语言:javascript
复制
Intent intent2 = new Intent(context, MainActivity.class);
intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setAction("android.intent.action.MAIN");
context.sendBroadcast(intent2);
票数 0
EN

Stack Overflow用户

发布于 2015-03-30 00:52:20

更改要打开应用程序并隐藏启动器图标的代码:

代码语言:javascript
复制
ComponentName componentName = new ComponentName(getContext(), YourReceiver.class);

不要忘记在清单中声明您的BroadcastReceiver

代码语言:javascript
复制
<receiver
   android:name="YourReceiver" >
   <intent-filter>
       <!-- your intent filter goes here -->
   </intent-filter>
</receiver>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29336206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档