0

I have made 2 apps. In the first app there is a string and a button. I want that after clicking on the button, the second app should be opened and that string should be passed to that app. How is this possible. This is my primary requirement. It would be great if the second app can not be opened directly. Only way to open it is by clicking on the button in the first app. If this is possible then let me know.

I am new to android so please help me.thanks in advance

priya
  • 163
  • 1
  • 3
  • 16
  • possible duplicate of [How to implement my very own URI scheme on Android](http://stackoverflow.com/questions/2448213/how-to-implement-my-very-own-uri-scheme-on-android) – SnyersK Jul 10 '15 at 09:05

2 Answers2

0

You can do this using implicit intent check Receiving/calling implicit intent and
Edit Check this question

Community
  • 1
  • 1
Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
  • I wish to use explicit intent. Is it possible – priya Jul 10 '15 at 09:09
  • yeah I did. How should I pass the string. And the second app can be opened directly as well. Any way to stop that? – priya Jul 10 '15 at 09:20
  • @palakarora you can use `intent.putString()` for passing string and is you don't want to show second app in home then remove `` from AndroidManifest – Jaiprakash Soni Jul 10 '15 at 09:23
  • how will the second app receive the string. and do I need to make any changes to the manifest of second app like adding intent filters or something like this – priya Jul 10 '15 at 09:28
  • @palakarora put srting using `intent.putExtra(key,value)` for receiving string second app you have to use `getIntent.getStringExtra(key)` in activity that will start – Jaiprakash Soni Jul 10 '15 at 09:31
0

Try as follows

    String app_Name ="com.package.name";
Intent intent = getPackageManager().getLaunchIntentForPackage(app_Name);
    if (intent != null) {
        // Activity now start the activity
        intent.putExtra("EXTRA_SESSION_ID", "Your variable Here");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        //Go to the market  
        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=" + app_Name));
        startActivity(intent);
    }

app_Name is variable.

Arshid KV
  • 9,631
  • 3
  • 35
  • 36