http://www.2cto.com/kf/201203/122910.html
Android SDK中有这样一个API:
public abstract Intent getLaunchIntentForPackage (String packageName)
如果packageName存在返回入口Intent, startActivity(Intent)可以启动应用,否则返回nullimport
android.app.Activity;
下面有个小示例:
- import android.content.Intent;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- import android.view.View;
-
- public class Main extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- PackageManager packageManager = getPackageManager();
- Intent intent=new Intent();
- intent =packageManager.getLaunchIntentForPackage("pkgName");
- if(intent==null){
- System.out.println("APP not found!");
- }
- startActivity(intent);
- }
- }
-
- mButton01.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
-
- Intent intent=new Intent();
- intent.setComponent(new ComponentName("com.droidnova.android.games.vortex",
- "com.droidnova.android.games.vortex..Vortex"));
- startActivity(intent);
- }
- });
-
- mButton02.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
- Intent intent=new Intent();
- intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));
- startActivity(intent);
- }
- });
//这些代码是启动另外的一个应用程序的主Activity,当然也可以启动任意一个Activity
ComponentName
componetName = new
ComponentName(
//这个是另外一个应用程序的包名
"com.poynt.weibo",
//这个参数是要启动的Activity
"com.poynt.weibo.ui.IndexActivity");
Android在一个应用中启动另一个应用的Activity
为 activity 添加 intent-filter
的定义。
通过测试发现,只要添加如下语句,activity就可以被正常调用:
<intent-filter>
<action
android:name=""/>
</intent-filter>
相应的启动代码为:
Intent
intent = new Intent();
intent.setClassName(<package name>,
<class
name>);
startActivity(intent);
android启动另一应用,布布扣,bubuko.com
android启动另一应用
原文:http://www.cnblogs.com/jiezzy/p/3750781.html