【问题标题】:unable to resolve ActivityNotFoundException无法解决 ActivityNotFoundException
【发布时间】:2012-06-13 07:06:01
【问题描述】:

我正在向这样的广播接收器发送意图。

Intent cpIntent = new Intent();
cpIntent.setClassName("com.android.contacts", "com.android.contacts.EABContactsAppReceiver");
cpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cpIntent.setAction(IMS_SUBSCRIBE); 
cpIntent.putExtra("contactid",contactid);
startActivity(cpIntent);

在接收端我接受的意图如下:

else if( intent.getAction().equals(ContactsListActivity.IMS_SUBSCRIBE )){ 
// this is a dummy event just to start the application
Log.d("ContactsAppReceiver", "IMS_SUBSCRIBE");
final String id = intent.getStringExtra("contactid");
Log.d(TAG,"id :"+id);

我还在Manifest 文件中声明了活动和意图过滤器。

<receiver android:name="com.android.contacts.EABContactsAppReceiver">
            <intent-filter>
                <!-- <action android:name="com.sec.android.app.sns.action.UPDATE_ACTIVITY" />
-->             <!--<action android:name="com.sec.siso.imsservice.IMS_SERVICE_READY_EVENT" />-->
                            <action android:name="android.intent.action.BOOT_COMPLETED"/>
                            <action android:name="android.intent.action.ACTION_SYNC_STATE_CHANGED"/>
                <!-- <action android:name="com.sec.android.app.sns.action.UPDATE_MESSAGE" />
-->
                <action android:name="com.sec.siso.SUBSCRIBE"/>
                <action android:name="com.sec.siso.logs.SUBSCRIBE"/>
            </intent-filter>
        </receiver>

但是我仍然收到ActivityNotFoundException。谁能帮我解决这个问题?

【问题讨论】:

  • 你把这个添加到android清单文件
  • 是的。我也将它添加到清单中。就像显示的那样。
  • 你能粘贴 logcat 条目吗?我只是想弄清楚错误在哪里。

标签: android android-intent broadcastreceiver intentfilter


【解决方案1】:

在您的第一个代码中,您尝试启动一项活动而不是发送广播。你应该替换

startActivity(cpIntent);

sendBroadcast(cpIntent);

【讨论】:

  • 没错! Intent 用于 3 个不同的目的:启动/与 Activity 通信、启动/与 Service 通信、发送广播。这些是完全不同的东西,你不能把它们混为一谈。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 2018-06-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
  • 2016-03-30
相关资源
最近更新 更多