简体   繁体   中英

get data onActivityResult from another application

I have two application A and B.

Application A

the following code I launch B Application for get Result from A application activity ..

   String packageName = "com.cm.applicationb";
            PackageManager manager = context.getPackageManager();
            Intent i = manager.getLaunchIntentForPackage(packageName);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            i.putExtra("grand_total", "2500");
            i.setAction(packageName);
            startActivityForResult(i, REQUEST_DATA);

From Application A call onActivityResutl

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==REQUEST_DATA)
        if (resultCode == Activity.RESULT_OK) {
            me=data.getStringExtra("Obj");
        }
    Toast.makeText(getApplicationContext(),me,Toast.LENGTH_LONG).show();
}

B Application setResult Data

     Intent i=new Intent();
                i.putExtra("Obj", "object");
                setResult(Activity.RESULT_OK, i);
                finish();

Ever retrun null data and resultcode from onActivityResult. How we can solve it? It is impossible get data onAcitivityResult from another applicaion setREsult. Anyone please help me for us. Thank you so much.

Remove finish() and call like this in B :

@Override
public void onBackPressed() { 
    Intent data = new Intent();

    Bundle bundle = new Bundle();
    bundle.putString("Obj", "Obj_Data");
    data.putExtras(bundle);

    setResult(Activity.RESULT_OK, data);
    super.onBackPressed(); // this calls finish(); internally.
}

just add this line to your manifest.xml

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

for more detail, check this links that explain about how to receive data from other application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM