launch an installed app with my own by pressing a button

社会主义新天地 提交于 2019-12-25 07:22:31

问题



How can I launch an app (3rd party app) that is installed on my phone with my own app? I'm having several buttons in my app and when one has pressed an app that is installed should open, for example, Bank of America app. (I want to create a customized menu). I totally new to android programming, but could it work like this? What URI string could I use or how do I figure it out? Thanks a lot!

Button b_boa = (Button) findViewById(R.id.button_boa); 
b_boa.setOnClickListener(new View.OnClickListener() { 

 @Override
 public void onClick(View v) {
      Intent open_boa = new Intent(Intent.ACTION_VIEW,
      Uri.parse("_________")); 
      startActivity(open_boa);
  }
});

回答1:


You can launch a different app from your application on click of a button or something with the package name and if you dont know the launching activity of the application to be opened..You can use this

Intent LaunchIntent =     getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);

and if you know the launching activity also which you can see from the manifest file of the app to be open then use this.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new    ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);


来源:https://stackoverflow.com/questions/18682512/launch-an-installed-app-with-my-own-by-pressing-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!