html5 唤起app

html5 测试代码

<html>
<head>
    <meta charset="utf-8">
head>
<body>
<h1>Test Schemeh1>

<a id="100" class="arouseApp" href="myscheme://http://196.168.2.1?key=mykey"><span>启动appspan>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>
            <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
html5 唤起app_第1张图片
— 点击加号 添加一个URL Schemes
html5 唤起app_第2张图片

- (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 就是从页面上跳转过来的参数
    }

你可能感兴趣的:(android,cocos,ios,html5,scheme,app)