0

I start an application with this code:

Intent hasApp = getPackageManager().getLaunchIntentForPackage("appName.app");
Intent intent = new Intent(Intent.ACTION_VIEW);
dataId = response.getdataId();
intent.setData(Uri.parse("appName:?pid=" + dataId + "&action=returntoapp"));
startActivityForResult(intent, Globals.DATA_REQUEST_CODE);

And i close the opened application with this code:

setResult(Activity.RESULT_OK);
finish();

But when the first app called the onActivityResult() method I got the same requestCode, but the intent is null, and the resultCode is ACTIVITY_CANCELED.

I don't understand why.

just
  • 1,900
  • 4
  • 25
  • 46

1 Answers1

0

Try this

String packageName = "com.example.app"

public static boolean openApp(Context context, String packageName) {
        PackageManager manager = context.getPackageManager();
        try {
            Intent i = manager.getLaunchIntentForPackage(packageName);
            if (i == null) {
                return false;

            }
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            context.startActivity(i);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
Sathish Kumar
  • 919
  • 1
  • 13
  • 27