admin管理员组

文章数量:1530517

一.使用Custom Scheme URI打开APP

此红色部分(自定义Uri)引用的博客是:http://blog.csdn/buptlzx/article/details/9837137

    就Android平台而言,URI主要分三个部分:scheme, authority and path。其中authority又分为host和port。格式如下:

scheme://host:port/path
举个实际的例子:
content://com.example.project:200/folder/subfolder/etc ?arg0=1&arg1=2
———/ —————————/ —/ ————————–/ ————————–/(query我们要传的值)
scheme host port path (我们要传的值如果是传多个值使用&)
——————————–/
authority

  1. android代码而言:主要有两块一部分是注册文件如下。
            <intent-filter>
                <data
                    android:host="com.example.project"
                    android:port="200"
                    android:scheme="content" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

2.另一部分就是app首页解析网页代码如下。

 Intent intent = getIntent();  
        Uri uri=intent.getData();  
        if(uri!=null){  
            String name=uri.getQueryParameter("arg0");  
            String name1=uri.getQueryParameter("arg1");  
            String scheme= uri.getScheme();  
            String host=uri.getHost();  
            String port=uri.getPort()+"";  
            String path=uri.getPath();  
            String query=uri.getQuery();  
        }

二.通过包名打开第三方app,如果没有包名就去指定地址下载对应的app

    try {
            Intent intent = wm.getPackageManager().getLaunchIntentForPackage(appPackageName);
            Bundle bundle = new Bundle();
            bundle.putString("s","d");
            intent.putExtras(bundle);
            wm.startActivity(intent);
            return;
        } catch (Exception e) {
            downloadAddress = downloadAdd;
            BaseDialog dialog = new BaseDialog();
            dialog.setTitle("提示");
            dialog.setContent("您还未下载“" + DelegateDataBase.ENTRUST_LIST[index] + "”是否进行下载?");
            dialog.setConfirm("下载", new BaseDialog.DialogListener() {
                @Override
                public void onListener() {
                        Uri uri = Uri.parse(downloadAddress.toString());
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        wm.startActivity(intent);
                    }

            });
            dialog.setCancel("取消", null);
            dialog.show(wm);
        }

本文标签: urlapp