Andoid实现Custom Protocol

Android中实现Custom Protocol,只需要简单的两步:

1、修改AndroidManifest.xml文件,在activity节增加以下内容:

            <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="myproto"/>
            </intent-filter>

2、修改对应activity中,用以下代码,就可以处理URL中的数据啦

        Intent intent = getIntent();
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            Uri uri = intent.getData();
            String user = uri.getQueryParameter("user");
            String password = uri.getQueryParameter("password");
            //do your job here
        }

Comments are closed.