I am searching for a possibility to call 3rd party apps by using the PackageManager
. The major problem is, that my method callApp
implements the interface of another solution, which is not accessable. I only recieve the parameter appName
without package-information.
When the Intent
is initialized, i have to add my packagepath (here: com.example) by hand.
I want to achieve, that Android finds the full name of the package, which matches to that name. Because this method is part of another project, i can not use getApplicationContext().getPackageName();
or similar. Any ideas?
public void callApp(int methodIndicator, String appName, String command, Map<String, String> args) {
PackageManager pm = context.getPackageManager();
// < Should only be the name
Intent launchIntent = pm.getLaunchIntentForPackage("com.example."+appName);
launchIntent.putExtra("method", methodIndicator);
launchIntent.putExtra("command", command);
launchIntent.putExtra("args", new HashMap<String, String>(args));
launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launchIntent);
}