2016-06-29 1 views
1

私は2つのアプリケーションA &を持っています。アプリケーションBでは、深いリンクとstartActivityForResult()を使用してアプリケーションBのアクティビティを開きます。返品、ちょうど受け取ったアプリA RESULT_CANCELED!私の最初の質問は、「別のアプリを開くためにDeep Linkを使用すると結果を返すことは可能ですか?」であり、そうであれば私のミスはどこですか?アプリケーションBでディープリンクを使用して別のアプリケーションを開くときの結果を返します

私のマニフェスト、:アプリケーションAでは

<activity android:name=".activity.TargetActivity"> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 

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

     <!-- Accepts URIs that begin with "http://www.example.com/gizmos” --> 
     <!-- note that the leading "/" is required for pathPrefix--> 
     <data 
      android:host="www.example.com" 
      android:pathPrefix="/gizmos" 
      android:scheme="http" /> 
     <data 
      android:host="www.example.com" 
      android:pathPrefix="/gizmos" 
      android:scheme="https" /> 
     <data 
      android:host="example.com" 
      android:pathPrefix="/gizmos" 
      android:scheme="http" /> 
     <data 
      android:host="example.com" 
      android:pathPrefix="/gizmos" 
      android:scheme="https" /> 
    </intent-filter> 
</activity> 

:また

  Uri webpage = Uri.parse("android-app://com.vancosys.payment/http/www.example.com/gizmos?name=FMarket&id=4231"); 

      Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage); 

      // Verify it resolves 
      PackageManager packageManager = getPackageManager(); 
      List<ResolveInfo> activities  = packageManager.queryIntentActivities(webIntent, 0); 
      boolean   isIntentSafe = activities.size() > 0; 

      // Start an activity if it's safe 
      if (isIntentSafe) 
      { 
       // '4231' is my request code 
       startActivityForResult(webIntent, 4231); 
      } 

:アプリケーションBで

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if(requestCode == 4231) 
    { 
     if (resultCode == RESULT_OK) 
     { 
      String id = data.getStringExtra("ID"); 

      Intent i = new Intent(this, ResultActivity.class); 
      i.putExtra("RESULT", true); 
      i.putExtra("ID", id); 
      startActivity(i); 
     } 
     else 
     { 
      // It JUST equals to RESULT_CANCELED!!! 
      Intent i = new Intent(this, ResultActivity.class); 
      i.putExtra("result", false); 
      startActivity(i); 
     } 
    } 
} 

そして最後に、:

     new Handler().postDelayed(new Runnable() 
         { 
          public void run() 
          { 
           Intent i = new Intent(); 
           TargetActivity.this.setResult(RESULT_OK, i); 
           i.putExtra("ID", "45651232"); 
           finish(); 
          } 
         }, 3000); 

更新日: Intent dataonActivityResult()nullです!!!

答えて

0
は、このようなあなたのApp Bのコードに変更し

:あなたの最初のコードが何をしているか

new Handler().postDelayed(new Runnable() 
        { 
         public void run() 
         { 
          Intent i = new Intent(); 
          i.putExtra("ID", "45651232"); 
          //setResult() method should be called after all the putExtra() methods 
          TargetActivity.this.setResult(RESULT_OK, i); 

          finish(); 
         } 
        }, 3000); 

をあなたが結果を設定した後、「ID」の余分を設定しているということです。 setResult()メソッドの前に行う必要があります。そうしないと、インテントの変更は結果に影響しません。 まず、Extraの値をIntentに設定してから、setResult()メソッドを使用します。

+0

ハズレを支援します!働いていない。返された意図はnullで結果コードはRESULT_CANCELEDです... – YUSMLE

+0

このハンドラが呼び出されたかどうかをチェックします。結果を設定せずにApp Bを閉じることができるかどうか確認します。 –

0

"onActivityResult"メソッドを使用しているアクティビティのマニフェストファイルにインテントフィルタを挿入すると、アプリケーションからデータを受け取ることができます。

<intent-filter> 
    <action android:name="android.intent.action.SEND" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 

希望これは、あなたは

+0

いいえ、まだ 'data == null '私の' onActivityResult() 'の中で。 – YUSMLE

関連する問題