android scheme 跳转应用 如何获取intent传的参数

首先需要在AndroidManifest.xml  修改

<activity android:name="com.test.apptest.AppActivity"

          android:label="@string/app_name"

          android:launchMode="singleTask”>//Activity的Launch mode详解


    <intent-filter>

        <actionandroid:name="android.intent.action.MAIN"/>

        <actionandroid:name="android.intent.action.VIEW"/>

        <categoryandroid:name="android.intent.category.LAUNCHER"/>

    intent-filter>


    <intent-filter>

        <action android:name="android.intent.action.VIEW" />

        <data android:scheme="apptest"/>

        <category android:name="android.intent.category.DEFAULT"/>

        <category android:name="android.intent.category.BROWSABLE"/>

    intent-filter>


activity>



singleTasksingleInstance方式

如果Activity 已经启动过了会重新唤醒  (从app 跳转到网页或其它app 在跳转回来)

protected void onNewIntent(Intent intent) {

   super.onNewIntent(intent);

   setIntent(intent);

   //here we can use getIntent() to get the extra data.

}

@Override
protected voidonResume() {
    super.onResume();
    onNewIntent(this.getIntent());
   Intent intent = getIntent();
    String scheme = intent.getScheme();
    Uri uri = intent.getData();
    System.out.println("scheme:"+scheme);
    if(uri != null) {
    String host = uri.getHost();
    String dataString = intent.getDataString();
    String id = uri.getQueryParameter("d");
    String path = uri.getPath();
    String path1 = uri.getEncodedPath();
    String queryString = uri.getQuery();
    System.out.println("host:"+host);
    System.out.println("dataString:"+dataString);
    System.out.println("id:"+id);
    System.out.println("path:"+path);
    System.out.println("path1:"+path1);
    System.out.println("queryString:"+queryString);
    }

}


如果Activity 没有启动过 则重新创建    (从网页或其它app  打开app)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    String scheme = intent.getScheme();
    Uri uri = intent.getData();
    System.out.println("scheme:"+scheme);
    if(uri != null) {
    String host = uri.getHost();
    String dataString = intent.getDataString();
    String id = uri.getQueryParameter("d");
    String path = uri.getPath();
    String path1 = uri.getEncodedPath();
    String queryString = uri.getQuery();
    System.out.println("host:"+host);
    System.out.println("dataString:"+dataString);
    System.out.println("id:"+id);
    System.out.println("path:"+path);
    System.out.println("path1:"+path1);
    System.out.println("queryString:"+queryString);
    }

}



 
  
 
  
 
  
 
  
 
  
 
  

    



你可能感兴趣的:(android)