1

I'm creating an android app which should open any other app on the mobile device using speech recognition ex- when user says "open facebook", then the app should open facebook ,same applies for all other apps on the phone. I'm able to do this for few apps but want a generalized way so that this functionality can be extended for opening all apps. Kind of like how google assistant opens any app for you. I'm using android studio. How to do it?

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
s.bhardwaj
  • 41
  • 3
  • "Okay Google" ? The issue is that you will have to create an intent to send users to another app and this opens an app chooser (except if the user already set a default app). Not sure it is possible to open specific app, try looking for the way launchers work, maybe it'll point you in the right direction. – Pierre P. Oct 10 '18 at 12:43

2 Answers2

2

You can do it, if you know the app name, with their package name, something like this

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (launchIntent != null) { 
    startActivity(launchIntent); //null pointer check in case package name was not found
}

for getting all the packages, may be you need to do bit research and run some service. May be you can use app stats to get that.

Check this if it helps:

Android, Detect when other apps are launched

itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
Uday Ramjiyani
  • 1,407
  • 9
  • 22
0

Use package name of the application to open it.

    Intent startIntent= getPackageManager().getLaunchIntentForPackage("com.package.xyz");
assert startIntent!=null; // check for null 
            startActivity(startIntent);
gmMustafa
  • 11
  • 4