从网页打开android intent并获取结果

Open android intent from web page and get result

本文关键字:获取 结果 intent android 网页      更新时间:2023-09-26

使用HTML/JavaScript,是否可以从特定应用程序调用Intent并从页面中获得返回?

我知道我可以在href属性中放入一些命令,比如<a href=tel:555498765432/>,以执行特定于电话的功能,但如果我想调用一个活动并从中获得回报呢?有类似<a href='intent:com.MyIntent'/>的东西吗?

当用户通过移动浏览器导航到应用程序时,您可以通过特定的url启动应用程序,为此,您必须为"活动"创建意向过滤器,例如:(假设用户应该导航到http://yourhost.com/startForValue?userid=1111)

<activity android:name=".YourActivity">
<intent-filter>
<data
 android:host="yourhost.com"
 android:path="/startForValue"
 android:scheme="http" />
<action android:name="android.intent.action.VIEW />
<category android:name="android.intent.category.DEFAULT />
<category android:name="android.intent.action.BROWSABLE />
</intent-filter>
</activity>

当活动启动时,您将能够通过从参数中获取用户id

String parameters = getIntent().getData().getEncodedQuery();

当用户完成必要的操作时,您可以发送带有所需数据和用户标识符的普通HTTP请求,以将数据与用户链接。当然,最好使用一些更安全的身份验证机制,如OAuth,但想法是一样的。