【问题标题】:Action Intent causing a ActivityNotFoundException while starting another activity启动另一个活动时导致 ActivityNotFoundException 的操作意图
【发布时间】:2013-04-08 08:38:53
【问题描述】:

启动 Activity 的我的 TestApp 具有以下代码:

public void startOperaView() {
        Intent browserIntent = new Intent("org.droidtv.nettvbrowser.VIEW");
        Uri luri = Uri.parse("connectedplanet.tv/olvs/test");

        //browserIntent.setClass(getApplicationContext(), Browser.class);
        //browserIntent.setAction("org.droidtv.nettvbrowser.VIEW");
        browserIntent.setType("application/vnd.droidtv.sta");
        browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        browserIntent.setData(luri);

        startActivity(browserIntent);
    }

并且包“org.droidtv.nettvbrowser”有如下AndroidManifest.xml文件:

<activity
            android:name="org.droidtv.nettvbrowser.Browser"
            android:configChanges="locale"
            android:label="@string/app_name" >
            <intent-filter>
             <action android:name="org.droidtv.nettvbrowser.VIEW" />
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
             <category android:name="android.intent.category.DEFAULT" />
             <data android:mimeType="application/vnd.droidtv.sta" />

            </intent-filter>
        </activity>

奇怪的是,如果我在意图中指定实际的包名称,它似乎可以正常工作,只有动作意图会抛出这些错误。任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: android android-intent android-2.2-froyo


    【解决方案1】:

    参考http://developer.android.com/guide/topics/manifest/activity-element.html可以尝试设置android:exported="true"

    android:exported
    

    活动是否可以由其他应用程序的组件启动 - 如果可以,则为“true”,否则为“false”。如果为“false”,则该活动只能由同一应用程序的组件或具有相同用户 ID 的应用程序启动。 默认值取决于活动是否包含意图过滤器。没有任何过滤器意味着该活动只能通过指定其确切的类名来调用。这意味着该活动仅供应用程序内部使用(因为其他人不知道类名)。所以在这种情况下,默认值为“false”。另一方面,存在至少一个过滤器意味着该活动是供外部使用的,因此默认值为“true”。

    此属性不是限制活动暴露给其他应用程序的唯一方法。您还可以使用权限来限制可以调用活动的外部实体(请参阅权限属性)。

    或者你可以参考这样的:

    <activity android:name="OutgoingCallBroadcaster"
            android:theme="@android:style/Theme.NoDisplay"
            android:permission="android.permission.CALL_PHONE"
            android:configChanges="orientation|screenSize|keyboardHidden">
        <!-- CALL action intent filters, for the various ways
             of initiating an outgoing call. -->
        <intent-filter>
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="tel" />
        </intent-filter>
        <intent-filter android:icon="@drawable/ic_launcher_sip_call">
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="sip" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="voicemail" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.item/phone" />
            <data android:mimeType="vnd.android.cursor.item/phone_v2" />
            <data android:mimeType="vnd.android.cursor.item/person" />
        </intent-filter>
    </activity>
    

    【讨论】:

    • 我也使用了 android:exported 标签。没有运气。我仍然遇到同样的错误。
    • 您可以尝试将您的两个意图操作/类别分开吗?
    • 你能详细说明你的意思吗?我是安卓新手。
    猜你喜欢
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2015-04-06
    • 2011-08-13
    • 2014-10-10
    • 2018-06-05
    • 1970-01-01
    • 2020-01-18
    相关资源
    最近更新 更多