如何在一个应用中 通过某个事件,而去启动另外一个已安装的应用。
写一个简单的Demo,我们的程序有俩个按钮
一个点击会启动自己写的应用
而另外一个按钮会启动系统自带的日历
一、新建一个Android工程命名为StartAnotherApplicationDemo.
二、修改main.xml布局,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Another Application"
/>
<Button
android:id="@+id/start_calender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Calendar"
/>
</LinearLayout>
三、修改主程序StartAnotherApplicationDemo.java代码如下:
package cn.caiwb.new;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class StartAnotherApplicationDemo extends Activity {
private Button mButton01,mButton02;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton01 = (Button)findViewById(R.id.button);
mButton02 = (Button)findViewById(R.id.start_calender);
//-----启动我们自身写的程序------------------
mButton01.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
//-----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
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);
}
});
}
}
分享到:
相关推荐
Android 开机自启动应用, BOOT_COMPLETED
Android开机自启动小示例
android开机启动指定的应用 浏览器 Activity
Android应用程序可以实现开机时启动相关应用 如service等 Android系统在开机启动时会发出一个系统广播"android intent action BOOT COMPLETED" 在接收到这个广播就可以实现开机自启动功能 下面就是一个...
我们手机上安装的应用默认是以GridView的形式排放的,本篇博客将讲述以ListView的形式获得所有应用,并且点击应用后可以启动。
Android应用开机自动启动代码Demo,下载后直接放在Android Studio里运行就可以
Android应用源码之Android中禁止某软件的安装_安装
一个简单案例,可获取android系统所有应用程序列表,实现点击列表中的某一项,打开相应的应用
一款实用Android平台上的应用开机启动项管理
大家最为熟悉的拨号盘或者短信应用,在第一次启动的时候,会有一定时间的白屏现象,其实,默认的情况下,android程序启动时,都会有一个黑屏或者白屏闪过的现象,在白屏或者黑屏过后才显示真正的应用界面。...
Android应用安装有如下四种方式 1.系统应用安装――开机时完成,没有安装界面 2.网络下载应用安装――通过market应用完成,没有安装界面 3.ADB工具安装――没有安装界面。 4.第三方应用安装――通过SD卡里的APK文件...
Android_gif应用启动动画,动画播放完后跳往自定义的主菜单
Android定时自动启动应用程序~~~~~~~
Android应用开机时自动启动 想要编写自启动应用的可以参考些源码!
可以实现手机开机重启的时候自启动,程序简单易懂,有注释,是利用广播实现的
Android Activity的四种启动模式及其应用场景 https://blog.csdn.net/qq_31939617/article/details/80696728
如果需要在Android开机时自动启动应用程序,可以通过响应android.intent.action.BOOT_COMPLETED广播消息来实现, Android系统启动结束时,会发出 android.intent.action.BOOT_COMPLETED 消息
在Android平台上实现应用的自启动功能。部分山寨机修改系统,可能会出现问题,
Android实例源码-应用启动应用退出&网络判断类安卓源代码(12例) 3G和wifi的切换监听 android 在线更新示例代码 android程序的自动更新 和 基于GPS定位的轨迹存储 app更新,实现service下载 ViewPager+Fragment侧滑...
一个app启动另一个app,这个玩法挺火的嘛,有没有试过更新QQ到5.1版本,QQ的健康里面就可以添加其他app,实现从QQ跳转到其他app应用,这里模拟写了一个demo