How do I pass parameters to android Intent in new scheme on chrome?

后端 未结 4 1457
陌清茗
陌清茗 2020-12-02 12:44

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/c

4条回答
  •  無奈伤痛
    2020-12-02 13:12

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

    Do Whatever
    

    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:

    Do Whatever
    

    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.

提交回复
热议问题