html5 唤起app

14 篇文章 0 订阅
10 篇文章 0 订阅
html5 测试代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<h1>Test Scheme</h1>
<!--自动加载隐藏页面跳转-->
<a id="100" class="arouseApp" href="myscheme://http://196.168.2.1?key=mykey"><span>启动app</span></a>
<script>
    var arouseApp = document.getElementsByClassName("arouseApp");
    alert(arouseApp["0"].href);
    arouseApp["0"].href =  "myscheme://" + location.href;
    alert(arouseApp["0"].href);
</script>
</body>
</html>


//android配置
AndroidManifest.xml
<activity
        <!--html切换到app时唤起的activity-->
        android:name=".MainActivity"  
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"
        android:exported="true">   //是否允许被其他Application的组件启动
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <!--需要添加下面的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"/>
            <data android:scheme="myscheme"/>
        </intent-filter>
</activity>
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent =getIntent();
        Log.e(TAG, "scheme:" +intent.getScheme());
        Uri uri =intent.getData();
        Log.e(TAG, "scheme: "+uri.getScheme());
        Log.e(TAG, "host: "+uri.getHost());
        Log.e(TAG, "port: "+uri.getPort());
        Log.e(TAG, "path: "+uri.getPath());
        Log.e(TAG, "queryString: "+uri.getQuery());
        Log.e(TAG, "queryParameter: "+uri.getQueryParameter("key"));
    }
}

//ios
配置scheme info — urlTypes
urlTypes
— 点击加号 添加一个URL Schemes
Schemes

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

    NSLog(@"application ---  openURL  scheme  = %@" ,[url scheme]);
    NSLog(@"application ---  openURL  query  = %@" ,[url query]);
    NSString * scheme1 = [url scheme];
    NSString * scheme2 = [NSString stringWithFormat:@"myscheme"]; //填写在urlTyoes里添加的scheme

    if([scheme1 isEqualToString:scheme2])//这两个相等的时候证明唤起的app是我们自定义的    
    {
     NSString *itemId = [[url query] substringFromIndex:[[url query]  rangeOfString:@"roomId"].location];
     //itemId 就是从页面上跳转过来的参数
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值