Android(安卓)在一个应用中如何启动另外一个已安装的应用!!!
16lz
2021-01-24
一、新建一个Android工程命名为StartAnotherApplicationDemo.
二、修改main.xml布局,代码如下:
[java] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="WelcometoMrWei'sBlog."
- />
- <Button
- android:id="@+id/button"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="StartAnotherApplication"
- />
- <Button
- android:id="@+id/start_calender"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="StartCalendar"
- />
- </LinearLayout>
三、修改主程序StartAnotherApplicationDemo.java代码如下:
[java] view plain copy
- packagecom.android.tutor;
- importandroid.app.Activity;
- importandroid.content.ComponentName;
- importandroid.content.Intent;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.widget.Button;
- publicclassStartAnotherApplicationDemoextendsActivity{
- privateButtonmButton01,mButton02;
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- mButton01=(Button)findViewById(R.id.button);
- mButton02=(Button)findViewById(R.id.start_calender);
- //-----启动我们自身写的程序------------------
- mButton01.setOnClickListener(newButton.OnClickListener(){
- publicvoidonClick(Viewv){
- //-----核心部分-----前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
- Intentintent=newIntent();
- intent.setComponent(newComponentName("com.droidnova.android.games.vortex",
- "com.droidnova.android.games.vortex..Vortex"));
- startActivity(intent);
- }
- });
- //-----启动系统自带的应用程序------------------
- mButton02.setOnClickListener(newButton.OnClickListener(){
- publicvoidonClick(Viewv){
- Intentintent=newIntent();
- intent.setComponent(newComponentName("com.android.calendar","com.android.calendar.LaunchActivity"));
- startActivity(intent);
- }
- });
- }
- }
转摘自:http://blog.csdn.net/Android_Tutor/article/details/5596494
更多相关文章
- Android中界面中有多个edittext,如何默认让第二个获取焦点
- Android调用系统设置
- android真机上 conn.getOutputStream()异常 Does not support ou
- Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
- 移动web开发常用JavaScript代码
- android intent 传递list或者对象
- Android(安卓)混淆问题排查
- EditText字数限制
- android联系人、短信、邮件url总结