如何使用Html实现调用安卓设备上的本地应用程序?
- 内容介绍
- 文章标签
- 相关推荐
本文共计526个文字,预计阅读时间需要3分钟。
微信如何通过HTML网页调用本地安卓app或iOS app?
以下是一个简单的示例,展示了如何在Android端使用XML代码来启动本地app:
xml
在HTML网页中,你可以使用以下JavaScript代码来启动本地app:
javascriptfunction launchApp() { // 启动Android app window.location.href='intent://com.liuan.jsrunapp/.MainActivity#Intent;end';
// 启动iOS app // window.location.href='weapp://com.liuan.jsrunapp';}
这样,当用户点击按钮时,他们就可以通过微信中的HTML网页启动本地app了。
微信如何通过Html网页调用本地安卓app 或者ios app?
android 端代码
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="schemas.android.com/apk/res/android" package="com.liuan.jsrunapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <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.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!--host可以不写--> <data android:scheme="ckck" /> </intent-filter> </activity> </application></manifest>package com.liuan.jsrunapp;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class MainActivity extends AppCompatActivity { TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView) findViewById(R.id.tv_main_show); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { String name = uri.getQueryParameter("name"); String scheme = uri.getScheme(); String host = uri.getHost(); String port = uri.getPort() + ""; String path = uri.getPath(); String query = uri.getQuery(); mTextView.setText("获得的数据name:" + name + "\n" + "scheme:" + scheme + "\n" + "host:" + "host:" + host + "\n" + "port:" + port + "\n" + "path:" + path + "\n" + "query:" + query); } }}Html 代码
<html><meta charset="UTF-8"><body><h1>webToApp</h1> <!--自动加载隐藏页面跳转--><!--手动点击跳转--><input type="text" value="哈喽啊 刘安" id="inputId"><a id="linkToCart" href="#">点我打开</a></body><script src="cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script><script type="text/javascript"> $(document).ready(function(){ //点击链接的时候调用 $("#linkToCart").click(function(){ //得到input的值 var id = $("#inputId").val(); //设置linkToCart的href的值 $("#linkToCart").attr("href","ckck://myProject.com:80/mypath?name="+id); }); });</script></html>本文共计526个文字,预计阅读时间需要3分钟。
微信如何通过HTML网页调用本地安卓app或iOS app?
以下是一个简单的示例,展示了如何在Android端使用XML代码来启动本地app:
xml
在HTML网页中,你可以使用以下JavaScript代码来启动本地app:
javascriptfunction launchApp() { // 启动Android app window.location.href='intent://com.liuan.jsrunapp/.MainActivity#Intent;end';
// 启动iOS app // window.location.href='weapp://com.liuan.jsrunapp';}
这样,当用户点击按钮时,他们就可以通过微信中的HTML网页启动本地app了。
微信如何通过Html网页调用本地安卓app 或者ios app?
android 端代码
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="schemas.android.com/apk/res/android" package="com.liuan.jsrunapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <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.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!--host可以不写--> <data android:scheme="ckck" /> </intent-filter> </activity> </application></manifest>package com.liuan.jsrunapp;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class MainActivity extends AppCompatActivity { TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView) findViewById(R.id.tv_main_show); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { String name = uri.getQueryParameter("name"); String scheme = uri.getScheme(); String host = uri.getHost(); String port = uri.getPort() + ""; String path = uri.getPath(); String query = uri.getQuery(); mTextView.setText("获得的数据name:" + name + "\n" + "scheme:" + scheme + "\n" + "host:" + "host:" + host + "\n" + "port:" + port + "\n" + "path:" + path + "\n" + "query:" + query); } }}Html 代码
<html><meta charset="UTF-8"><body><h1>webToApp</h1> <!--自动加载隐藏页面跳转--><!--手动点击跳转--><input type="text" value="哈喽啊 刘安" id="inputId"><a id="linkToCart" href="#">点我打开</a></body><script src="cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script><script type="text/javascript"> $(document).ready(function(){ //点击链接的时候调用 $("#linkToCart").click(function(){ //得到input的值 var id = $("#inputId").val(); //设置linkToCart的href的值 $("#linkToCart").attr("href","ckck://myProject.com:80/mypath?name="+id); }); });</script></html>
