【问题标题】:Activity not appearing on Chooser dialog when using Implicit Intent使用隐式意图时,活动未出现在选择器对话框中
【发布时间】:2014-10-11 12:44:46
【问题描述】:

我想从另一个应用程序 IntentsLab 启动 MyBrowser,这是一个显示网页的应用程序,例如内置浏览器应用程序。

我按照Launch custom android application from android browser 设置了意图,还有the official Intent and Intent-filters guide 确实说“您需要包含 CATEGORY_DEFAULT 才能接收隐式意图”。

所以我的意图过滤器是这样写的:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.categroy.DEFAULT" />
            <data android:scheme="http" />
        </intent-filter>

IntentsLab中父Activity启动新Activity的代码为:

    Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
    String title = "Use Browser";        
    Intent chooserIntent = Intent.createChooser(baseIntent, title);        
    if(chooserIntent != null)   startActivity(chooserIntent);

MyBrowser 应用程序未显示在选择器对话框中。但是,当我在 IntentsLab 中创建一个 Activity 并向其添加相同的意图过滤器时,此 Activity 会显示在选择器对话框中。代码有什么问题吗?或者在同一个应用程序中对活动的隐含意图与在不同应用程序中的活动之间有什么区别?

【问题讨论】:

    标签: android android-intent intentfilter


    【解决方案1】:

    为 MyBrowserActivity 提供了我的 AndroidManifest.xml。它非常适合我。甚至我也在上 coursera Android 编程课 :)

    <activity android:name=".MyBrowserActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="http" />
    
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <!-- TODO - Add necessary intent filter information so that this
                        Activity will accept Intents with the
                        action "android.intent.action.VIEW" and with an "http"
                        schemed URL -->
    </activity>

    【讨论】:

      猜你喜欢
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2017-05-27
      相关资源
      最近更新 更多