简体   繁体   English

从Chrome内启动自定义网址计划的Android应用?

[英]Android app with custom URL scheme launching from within Chrome?

I created a basic Android app from the Eclipse wizard. 我从Eclipse向导创建了一个基本的Android应用程序。 I then added the following intent filter to AndroidManifest.xml , after the existing one. 然后,在现有的Intent过滤器之后,将以下intent过滤器添加到AndroidManifest.xml中 This makes it support a custom "sample://" URL scheme: 这使它支持自定义的“sample://”URL方案:

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

If I run Chrome or the default browser, and click a "sample://" link, it launches my app. 如果我运行Chrome或默认浏览器,然后单击“ sample://”链接,它将启动我的应用程序。 However, if I look at the task switcher, my app isn't listed. 但是,如果我查看任务切换器,我的应用程序未列出。 Instead, Chrome is shown, with my app's screen shot. 而是显示了Chrome,并显示了我的应用程序的屏幕截图。

Why is this? 为什么是这样? Can it be fixed? 可以修复吗? I'm running Android 4.2.2 on a Galaxy Nexus phone. 我在Galaxy Nexus手机上运行Android 4.2.2。

I notice that if I add android:launchMode="singleInstance" to the activity, it opens in a separate app. 我注意到,如果将android:launchMode="singleInstance"到活动中,它将在单独的应用程序中打开。 But the docs say this is "not recommended for general use". 文档称这是“不推荐用于一般用途”。 Why not? 为什么不?

The reason why you Activity appears in Recent Apps as Chrome is because it now belongs to the Chrome task, because it was launched from there. 您的Activity之所以在Chrome的“最新应用”中显示,是因为它现在属于Chrome任务,因为它是从那里启动的。

As you noticed android:launchMode="singleInstance" solves your problem, however it is not recommended or discouraged because it would brake the user experience and navigation and how users expect your application to behave. 正如您注意到android:launchMode="singleInstance"解决了您的问题,但不建议或不鼓励它,因为它会android:launchMode="singleInstance"用户体验和导航以及用户期望您的应用程序的行为方式。

Fortunately, I think there's a way of specifying Intent flags in your HREF , try something like this: 幸运的是,我认为可以在HREF中指定Intent标志的方法,请尝试如下操作:

<A HREF="intent:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.example.package/.MyActivity;end" />

in the previous example launchFlags=FLAG_ACTIVITY_NEW_TASK . 在前面的示例中, launchFlags=FLAG_ACTIVITY_NEW_TASK This flag is generally used by activities that want to present a "launcher" style behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them. 此标志通常由想要呈现“启动器”样式行为的活动使用:它们为用户提供可以完成的单独事物的列表,否则完全独立于启动它们的活动。

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

相关问题 自定义URL方案不启动Android应用程序 - Custom URL Scheme not launching the android application 通过Chrome浏览器中的网址启动Android应用 - Launching Android App from through url from Chrome browser 在Android中使用Google Chrome浏览器自定义URL方案? - Custom URL scheme with Google Chrome in Android? URL方案(imdb:///,linkedin://)无法在Android设备中启动应用 - URL Scheme (imdb:///, linkedin://) not launching app in Android device Android应用:如何从自定义网址方案中读取参数? - Android App: How to read get parameters from a custom url scheme? Android从Facebook应用程序打开自定义URL方案 - Android open custom url scheme from facebook app 使用自定义URL方案启动另一个应用程序将在启动应用程序的边界内打开该应用程序。 - Launching another application using custom URL scheme opens the application within the boundaries of the launching application. Salesforce Android应用中的自定义URL方案 - Custom url scheme in salesforce android app 使用自定义URL方案打开Android App - Open Android App with custom URL scheme 带有自定义方案的 Android 免安装应用深层链接:UNKNOWN_URL_SCHEME - Android instant app deeplink with custom scheme: UNKNOWN_URL_SCHEME
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM