Html5调起安卓APP

1 需要在AndroidManifest.xml 中添加过滤器

<activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>

                <data
                    android:scheme="myscheme"
                    android:host="myhost"
                    android:pathPrefix="/myapp/open"
                    />
            intent-filter>
        activity>

2 Html5代码

 
  <html >
<meta charset="utf-8">
  <script>
    function openapp(){
            window.location.href = 'myscheme://myhost/myapp/open?data=mydata'; 
    }
script>
  <body>
  <input type="button" value="打开app" onclick="openapp()">
  body>
  html>

3 在mainActivity中可以对传递过来的数据进行处理

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Uri uridata = this.getIntent().getData();
        String mydata = uridata.getQueryParameter("data");
    }

你可能感兴趣的:(Html5调起安卓APP)