Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

How to call one android application from another android application

I want to call one android application from another application

I have tried some examples, but they are not working for me, I'm getting a Package parse error.

Consider there are two applications: Application1 and Application2

I want to call Application2 from Application1

Here is the some sample code to do this:

Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(fileName),"application/vnd.android.package-archive"); 
startActivity(i);

Here fileName = "file://data/data/package_name/files/Application1.apk";

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think this code will help:

Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);

if(list.size() > 0)
{
 Log.i("Log", "Have application" + list.size());
 startActivity(intent);
}
else
{
    Log.i("Log", "None application");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...