1

最近,我安装了一个android应用程序,我发现当我Url在手机浏览器中浏览特定的(应用程序应该在后台运行)时,应用程序会自动启动。我想知道如何做到这一点?我试着用

"intent-filter <data schema:"http" android:host="*****" />

,但它与该应用程序的工作方式不同(自动启动)。我将有关该程序如何执行的视频上传到 youtube,youtube 链接。您可以在这里下载应用程序:baidu_map_download

具体网址: http: //map.baidu.com/mobile/zt/locshare

4

1 回答 1

0

作为开发人员,您对此只有被动影响。基本上,在您的清单中,您可以为您的活动设置一个 IntentFilter。例如,你的主 Activity 应该有 Intents android.intent.action.MAIN 和 android.intent.category.LAUNCHER。

例子:

<activity
        android:name=".ui.activities.MainActivity"
        android:label="@string/app_name">
    // Here the Intent Filter is set
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

如果您希望您的应用程序由特定的 Intent 启动 - 您可以在此处查找任何可用的 Intent - 您必须将此 Intent 添加到 IntentFilter。然后,智能手机的用户可以从在其 IntentFilter 中具有此 Intent 的所有应用程序中选择一个 Intent 的默认应用程序

编辑1:

您可以为特定 Intent 显示一个选择器对话框,让用户可以为该 Intent 选择默认应用程序,如下所示:

Intent intent = new Intent(Intent.ACTION_VIEW);
String title = getString(R.string.chooser_title);
Intent chooserIntent = Intent.createChooser(intent, title);
startActivity(chooserIntent);

编辑2:

这个 IntentFilter 处理所有指向 google.com 的链接

<intent-filter>
    <data android:scheme="http" android:host="google.com"/>
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

将其添加到清单中的应用程序标签中,当您浏览属于该类别的 url 时,您的应用程序将启动。

于 2013-11-04T10:59:58.477 回答