简体   繁体   English

无法使用仅指定动作的隐式意图来启动活动

[英]Unable to launch an activity using implicit intent specifying only action

I am trying to launch an activity by specifying only its action(custom) defined in its intent filter from an activity in other application. 我试图通过仅从其他应用程序中的活动中指定其意图过滤器中定义的活动(自定义)来启动活动。 The activity to be launched is the main activity of its application thus have android.intent.action.MAIN & android.intent.category.LAUNCHER set as action and category in its intent filter. 要启动的活动是其应用程序的主要活动,因此在其意图过滤器中将android.intent.action.MAINandroid.intent.category.LAUNCHER设置为操作和类别。 Now according to android doc on Intent and Intent Filter, i do not need to specify DEFAULT category at all in this case. 现在根据Intent和Intent Filter上的android doc,在这种情况下,我根本不需要指定DEFAULT类别。 But doing the same i am i am unable to launch the activity. 但是我同样无法启动活动。

LogCat says, Activity could not be found... LogCat说,找不到活动...

Am i misinterpreting the text or is there something else missing...? 我是在误解文字还是缺少其他内容...?

Code, used for calling the activity 用于调用活动的代码

Intent i=new Intent();
i.setAction("android.AddressBookV4.firstActivity");
startActivity(i);

Definition of Activity being called in the manifest file 在清单文件中调用的Activity的定义

<activity android:name=".AddressBook"
          android:label="@string/app_name">
     <intent-filter>
         <action android:name="android.AddressBookV4.firstActivity" />
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

You need to add the LAUNCHER category to your Intent , since the <intent-filter> says that it matches the following Intents (in pseudocode): 您需要将LAUNCHER类别添加到您的Intent ,因为<intent-filter>表示它与以下Intent(以伪代码)匹配:

((action IS "android.AddressBookV4.firstActivity")
    OR (action IS "android.intent.action.MAIN"))
  AND (category IS "android.intent.category.LAUNCHER")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM