使用HTML / JavaScript,是否可以从特定应用调用Intent并从页面中返回?
我知道我可以在href属性中添加一些命令,比如<a href=tel:555498765432/>
来执行特定于手机的功能,但是如果我想调用一个活动并从中获取回报怎么办?是否有类似<a href='intent:com.MyIntent'/>
的内容?
答案 0 :(得分:1)
当用户通过移动浏览器导航时,您可以通过特定网址启动您的应用,为此您必须为您的活动创建intent filter,例如:(假设您的用户应导航至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>
当活动开始时,您将能够通过
从参数中获取用户IDString parameters = getIntent().getData().getEncodedQuery();
当用户完成必要的操作时,您可以发送带有所需数据和用户标识符的普通HTTP请求,以将数据与用户链接。当然,最好使用像OAuth这样更安全的身份验证机制,但这个想法是一样的。