如何在 chrome 上的新方案中将参数传递给 android Intent? [英] How do I pass parameters to android Intent in new scheme on chrome?

查看:23
本文介绍了如何在 chrome 上的新方案中将参数传递给 android Intent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络应用程序通过 iframe Intent 在 android 上调用本机应用程序,根据以下内容在 chrome 25 中不起作用......

https://developers.google.com/chrome/mobile/docs/intents>

意图的结构如下......

app://Requesttype=Testing&Type=123&tn=0000000000

在新的 intent://方案中,我将如何将 app://后面列出的参数传递给本机应用程序?我一直没能找到一个例子.

解决方案

使用新方案,您可以将参数作为附加项传递给应用程序,但必须对 URI 进行如下编码:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.myextra=mystring;end">做任何事</a>

这将传递一个名为myextra"的额外字符串,其值为mystring".看看 Android Code 我们可以看到额外的参数需要如何编码.myextra"参数开头的S"将其定义为字符串.其他类型可以是:

String =>'S'布尔值 =>'B'字节 =>'乙'字符 =>'C'双 =>'d'浮动 =>'F'整数 =>'一世'长 =>'我'短 =>'s'

例如,如果我们想传递两个额外的参数,一个整数和一个字符串,我们可以这样做:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.name=Perico%20de%20los%20Palotes;i.age=35;end">做任何事情

请注意,您需要对所有参数进行 url 编码.

在您的 Android 应用中,您需要接受这些附加功能.在您的活动的onCreate"事件中:

Bundle parametros = getIntent().getExtras();如果(额外的!= null){String name = extras.getString("name");整数年龄 = extras.getInt("age");if (name!=null && age!=null){//做任何你必须做的事//...}}别的{//没有额外的,克服它!}

当然,还要在清单中添加过滤器 android.intent.category.BROWSABLE,如此链接.

I have a web app calling a native app on android via an iframe intent which does not work in chrome 25 according to the following....

https://developers.google.com/chrome/mobile/docs/intents

The intent was structured like the following....

app://Requesttype=Testing&Type=123&tn=0000000000

In the new intent:// scheme how would I go about passing the parameters listed after app:// to the native application? I haven't been able to find an example.

解决方案

With the new scheme, you can pass arguments as extras to the App, but you must encode the URI as follows:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.myextra=mystring;end">Do Whatever</a>

This will pass an extra String called "myextra" with the value "mystring". Having a look at the Android Code we can see how the extra parameters need to be coded. The "S" at the beginning of the "myextra" parameter defines it as a String. Other types can be:

String => 'S'
Boolean =>'B'
Byte => 'b'
Character => 'c'
Double => 'd'
Float => 'f'
Integer => 'i'
Long => 'l'
Short => 's'

For example, if we want to pass two extra parameters, an Integer and a String, we can do this:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.name=Perico%20de%20los%20Palotes;i.age=35;end">Do Whatever</a>

Note that you'll need to url-encode all the parameters.

In your Android app, you'll need to accept those extras. In the "onCreate" event of your Activity:

Bundle parametros = getIntent().getExtras();
if (extras != null){
    String name = extras.getString("name");
    Integer age = extras.getInt("age");

    if (name!=null && age!=null)
    {
       //do whatever you have to
       //...
    }
}else{
     //no extras, get over it!!
}

And, of course, add the filter android.intent.category.BROWSABLE in your manifest as shown in this link.

这篇关于如何在 chrome 上的新方案中将参数传递给 android Intent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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