How to use putExtra to open another app and send some data for it?

Viewed 7120

I have two apps (A, B) that I want to link them together. When the user is in app A, by clicking on a button I want to open app B and send some data to it.

I used this method in app A to go app B and send some data to app B:

public static boolean openApp(Context mContext, String packageName) {
    PackageManager manager = context.getPackageManager();
    Intent goToEncyclopedia = manager.getLaunchIntentForPackage(packageName);
    if (goToEncyclopedia == null) {
        return false;
    }
    goToEncyclopedia.addCategory(Intent.CATEGORY_LAUNCHER);
    goToEncyclopedia.putExtra("NAME" , "Ehsan");
    context.startActivity(goToEncyclopedia);

    return true;
}

and I Call it like this in app A:

openApp(mContext, "encyclopedia.rasad.app.codenevisha.com.encyclopedia");

When I call this method it will open app B but data that I want to send with putExtra will not send.

And this is my code in App B to receive data from intent:

Bundle bundle = getIntent().getExtras();
if (bundle != null){
    String name = bundle.getString("NAME");
    Log.i("EXTRAS", name);
}
2 Answers
Related