0

In my application I need to open an explicit activity of another app from my app using intent and show the data send by my intent , data is a url most of the time. For example if my app shows some news from times of India app or some other news app , How can I open that particular news app redirected with news clicked by user.

I am using below code for Dailymotion app :

 Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse(newsFeedsList.get(getPosition()).getStrNewsLink()));
                                intent.setClassName(packageName, "com.dailymotion.dailymotion.mobile.activity.InterstitialActivity");
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                context.startActivity(intent);

It is working fine , but what if I dont have the name of class name for particular activity ? Please suggest!!

Nibha Jain
  • 7,742
  • 11
  • 47
  • 71
  • 1
    The proper way of opening the specific activity should be done using deep links.Some app developers do publish their deep links, so you need to check it with that particular app – Gautam Aug 24 '16 at 12:10
  • I read about it , but what if we don't have deep link of that app .. ? is there any solution in that case ? – Nibha Jain Aug 24 '16 at 12:50
  • @NibhaJain Hi nibha. I think u forgot me ! But regarding to your question what about deep linking. I haven't implemented it but i have just heard about that ! – Piyush Aug 24 '16 at 12:55
  • @PiyushGupta : I do remember you :) Please suggest if there is any possibility – Nibha Jain Aug 24 '16 at 13:13
  • @NibhaJain Check this pls http://search-codelabs.appspot.com/codelabs/android-deep-linking#9 – Piyush Aug 24 '16 at 13:16
  • @NibhaJain in that case you have to know the classname beforehand. There are ways to get the specific classes too , but you won't be knowing how the app will behave if you just use those classes since activities might be expecting some pre loaded data. – Gautam Aug 25 '16 at 05:50

3 Answers3

0

is sharedUserId used in both apps same? then use below code

Intent res = new Intent();
String mPackage = "com.your.package";
String mClass = ".actYouAreLaunching";
res.setComponent(new ComponentName(mPackage,mPackage+mClass));
startActivity(res);

code taken from below url Android Intents: Start activity using class name from another app that has the same sharedUserId

Community
  • 1
  • 1
Amod Gokhale
  • 2,346
  • 4
  • 17
  • 32
0

What data are you trying to pass to the other app? You can use:

intent.putExtra(key name, key value);

And then to retrieve the data:

String x = intent.getExtra(key name, key value);
tccpg288
  • 3,242
  • 5
  • 35
  • 80
0

you can start by having just the package name of other app. and if the other app handles it correctly you would get what you want. for example I've test this code on google youtube app !!!

PackageManager packageManager = getPackageManager();
    String packageName = "com.google.android.youtube";
    Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("https://www.youtube.com/user/queenofficial"));
    startActivity(intent);

and if you wanna get packages installed in your phone you can use List getInstalledApplications (int flags) in PackageManager class

hope this help :)

  • getLaunchIntentForPackage() will return the LauncherActivity ..But In my case it is not necessary to open LauncherActivity , it could be another activity of that app – Nibha Jain Aug 24 '16 at 12:39
  • Yes, that's true it's not exact answer .but some times as i said in my reply works because the app handles your intent and opens the activity you wanted like the youtube app – Mehdi Hamzezadeh Aug 25 '16 at 05:38