以URI数据通过意图的android [英] Taking uri data through intent in android
问题描述
我有Android应用程序和浏览器之间做连接。因此,点击浏览器按钮,而它应该重定向到Android应用程序。在Android的活动我已经写了
Hi i have to do connectivity between android app and browser. So while clicking a button on browser it should redirect to android app. in android activity i have written
Uri data = getIntent().getData();
if (data.equals(null)) {
System.out.println("Data is null");
} else {
String scheme = data.getScheme();
System.out.println(scheme);
String host = data.getHost();
int port = data.getPort();
List<String> params = data.getPathSegments();
String first = params.get(0); // "hello"
System.out.println(first);
和清单中我已经给
<intent-filter>
<data android:scheme="Integration" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
在HTML按钮点击我已经给了&LT; FORM METHOD =LINKACTION =整合:// 1&GT;
in html on button click i have given <FORM METHOD="LINK" ACTION="Integration://1">
这是扔indexoutofboundexception。 请告诉我哪里是错
it is throwing a indexoutofboundexception. Please tell me where is the mistake
更新 * 我使用意图在活动中不必要的。通过消除我的应用程序现在已经成功运行参数n在HTML5。的*
推荐答案
从报价回答:的如何监听一个自定义的URI
要注册一个协议,在你的Android应用程序,添加一个额外的块到AndroidManifest.xml中
To register a protocol in your android app, add an extra block to the AndroidManifest.xml
我修改了codeA一点,但认为我会注明出处太
I modified the code a little, but thought I'd quote the source too
<manifest>
<application>
<activity android:name=".activityToCall">
<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="scheme" android:host="path"/>
</intent-filter>
</activity>
</application>
</manifest>
然后一个URL匹配您的模式打开时,你的应用程序将被调用来处理它,我认为。
由于考虑到计划
和路径
对应于此:
Then when a url matching your schema is opened your app will be called to handle it I assume.
Taking into consideration that scheme
and path
correspond to this:
scheme://host/path
在此之后,在您在清单已设置来处理这些东西的活动:
After that, in the activity you've set in the manifest to handle this stuff:
Uri data = getIntent().getData();
if (!data.equals(null)){
String scheme = data.getScheme();
//Or whatever you needed
}
这篇关于以URI数据通过意图的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!