从调用浏览器Android应用程序 [英] Invoke android application from browser

查看:183
本文介绍了从调用浏览器Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图调用浏览器从我的应用程序的的Andr​​oid 3.1(蜂巢)
这是我试过的联系,但是这些工作:

I have been trying to invoke my application from browser on android 3.1 (Honeycomb) These are the links I tried, but none of these worked:

<a href="com.nk.myapp://movieid=95319">click me 1</a>

<a href="intent:#Intent;action=com.nk.myapp.detail;end">click me 2</a>

<a href=intent:#Intent;action=com.nk.myapp.detail;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.nk.myapp;end>click me 3</a>

有关第一和第二网址,它给了网页无法使用。

For 1st and 2nd url, it gives "Webpage not available".

有关第三之一,它显示应用市场与搜索:PNAME:com.nk.myapp - >未找到任何结果

For 3rd one, it shows Apps-market with search: pname:com.nk.myapp --> "No Result found".

应用仍处于开发阶段,所以它不是在市场上还没有。

Application is still in development, so its not in the market yet.

这是我的清单文件的样子:

This is how my manifest file looks like:

<activity
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:name=".MainActivity"
    android:screenOrientation="landscape" >
    <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter >
        <action android:name="com.nk.myapp.action.DIALOG" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <intent-filter >
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name=".WebViewActivity"
    android:screenOrientation="landscape" >
    <intent-filter>
        <data android:scheme="com.nk.myapp" />
        <action android:name="com.nk.myapp.detail" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

让你觉得我在做什么错了我知道了。

Let me know if you find what I am doing wrong.

推荐答案

下面是另一种方式来做到这一点:

Here is Another way to do it:

要找到URI,这就是我的测试APK补充说:

To find out uri, this is what I added in Test Apk:

Intent i = new Intent();
i.setAction("com.appname.NK_CUSTOM_ACTION");
i.putExtra("movie_id", "123456");
Log.e("IntentTest", i.toUri(Intent.URI_INTENT_SCHEME));

将会产生此字符串:

Which produces this string:

intent:#Intent;action=com.appname.NK_CUSTOM_ACTION;S.movie_id=123456;end

HTML页面有此链接:

Html page has this link:

<a href="intent:#Intent;action=com.appname.NK_CUSTOM_ACTION;S.movie_id=123456;end">click to load</a>

和,清单文件改为

<activity
    android:name=".TestActivity"
    android:screenOrientation="sensorLandscape" >
    <intent-filter>
        <action android:name="com.appname.NK_CUSTOM_ACTION" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

在测试活动,你就会得到movie_id下code:

In TestActivity, you get movie_id in code below:

Intent intent = getIntent();
String data = intent.getStringExtra("movie_id");

这篇关于从调用浏览器Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆