Android多屏意图过滤器
我想使用基于方案的意图过滤器从 Android 中的网络浏览器启动我的应用程序,像这样托管在 DATA 标签中。
<activity android:name=".activity.LogoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.phone.MainActivityPhone" android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<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="my" android:host="mystore" />
</intent-filter>
</activity>
<activity android:name=".activity.tablet.MainActivityTablet" android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<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="my" android:host="mystore" />
</intent-filter>
</activity>
如您所见,手机和平板电脑有两个Main Activity,在LogoActivity中根据屏幕大小确定将打开哪个Main Activity。但问题是,当用户在网络浏览器中单击 my://mystore 链接时,有两种选择来启动 MainActivtyPhone 和 MainActivityTablet。
我想要的是只有一个合适的意图过滤器适用于 uri my://mystore 。 有什么帮助吗?谢谢。
I want to launch my application from web browser in Android using Intent-Filter based on scheme, host in the DATA tag like this.
<activity android:name=".activity.LogoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.phone.MainActivityPhone" android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<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="my" android:host="mystore" />
</intent-filter>
</activity>
<activity android:name=".activity.tablet.MainActivityTablet" android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<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="my" android:host="mystore" />
</intent-filter>
</activity>
As you see, There are two Main Activities for phone and tablet, and in LogoActivity determine which Main Activity will be opened by screen size. But the problem is when user clicks my://mystore link in web browser, there are two choices to launch that MainActivtyPhone and MainActivityTablet.
What I want is there is only one proper intent-filter works for uri my://mystore .
Any help? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首次运行应用程序时,使用
PackageManager
禁用您不想使用的 Activity。请不要发明自定义方案。请改用 HTTP URL:
这样,您实际上可以在
http://yourdomain.com/something/or/another
上放置一个真实的网页,这样如果有人获取您的链接但没有您的安装应用程序后,他们将看到您的网页,而不是收到错误。另外,请删除
android:configChanges
,或处理所有配置更改。On the first run of your application, use
PackageManager
to disable the activity you do not want to use.Please do not invent custom schemes. Please use HTTP URLs instead:
That way, you can actually put a real Web page at
http://yourdomain.com/something/or/another
, so if somebody gets your link but does not have your app installed, they will see your Web page, instead of getting an error.Also, please remove
android:configChanges
, or handle all configuration changes.