这个例子实现了一个小程序,这个程序的特殊之处在于只要运行一次,然后它就会伴随着手机的启动而自己运行。
首先,为了捕捉手机启动的事件,我们需要在AndroidManifest.xml文件中添加如下的代码:
<!-- 委派receiver名稱為類別名稱 -->
<receiver android:name="HippoStartupIntentReceiver" >
<!-- 在filter裡設定BOOT_COMPLETED為要捕捉的訊息 -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
其中:
android.intent.action.BOOT_COMPLETED
这行代码是接收系统发送的广播事件。
下面给出这个程序的完整代码:
1.主程序的代码
这段代码其实就是提供一个Activity UI界面,不负责接收系统广播
public class EX06_16 extends Activity
{
/* 本程序只需运行一次,就会?日后开机时自动运行 */
private TextView mTextView01;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* 为了快速示意,程序仅一欢迎的TextView文字作为演示 */
mTextView01 = (TextView)findViewById(R.id.myTextView1);
mTextView01.setText(R.string.str_welcome);
}
}
2.广播接收器
public class EX06_16 extends Activity
{
/* 本程序只需运行一次,就会?日后开机时自动运行 */
private TextView mTextView01;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* 为了快速示意,程序仅一欢迎的TextView文字作为演示 */
mTextView01 = (TextView)findViewById(R.id.myTextView1);
mTextView01.setText(R.string.str_welcome);
}
}
分享到:
相关推荐
Android应用程序可以实现开机时启动相关应用 如service等 Android系统在开机启动时会发出一个系统广播"android intent action BOOT COMPLETED" 在接收到这个广播就可以实现开机自启动功能 下面就是一个...
Android 开机自启动应用, BOOT_COMPLETED
可以实现手机开机重启的时候自启动,程序简单易懂,有注释,是利用广播实现的
Android应用开机自动启动代码Demo,下载后直接放在Android Studio里运行就可以
Android的文件浏览器/文件选择器,可以集成到应用程序中,从内部/外部存储中浏览/选择文件。
android-sdk\platforms\android-21
客户需要开机后自动启动wifi-adb服务,所以就在程序里加了一下,开机后会自动打开wifi-adb连接服务,前提是的设备wifi是ok的,就可以通过wifi 来连接adb了。
android-support-v4-v7-v13-v14-v17(官方最新完整版),官方最新版的,压缩包内包含android-support-v4、android-support-v7-appcompat,android-support-v7-cardview,android-support-v7-gridlayout,android-support-...
【Android】开机自启动Demo 相关文章:http://blog.csdn.net/etzmico/article/details/6848465
宝利通rpm-android-phone-release-3.7-64806移动应用程序是一个易于使用的视频系统,提供优质的音频和视频体验。与专有应用程序不同,RealPresence移动应用程序是基于标准的,可扩展您组织的视频网络,使您在任何...
这里说个题外话,手机软件除非特殊情况,不然最好不要做开机自启动,开机自启动一般适用于android系统的终端机上,开机即运行相应的项目,该机器上也只有这个项目,下面上代码。 新建一个类AutoSta
# mv /opt/android-sdk/platforms/android-25/android-7.1.1/* /opt/android-sdk/platforms/android-25/ # rm -rf /opt/android-sdk/platforms/android-25/android-7.1.1 官网下载地址:...
Android应用开机时自动启动 想要编写自启动应用的可以参考些源码!
【Android】开机自启动Service Demo 相关文章链接:http://blog.csdn.net/etzmico/article/details/7317695
使用: export ANDROID_HOME="/opt/android-...# mv /opt/android-sdk/platforms/android-8.0.0 /opt/android-sdk/platforms/android-26 官网下载地址:https://dl.google.com/android/repository/platform-26_r01.zip
Android开机自启动小示例
http://s1.eoeandroid.com/sdk/4.1/android-sdk_r20-windows.zip(推荐) http://s1.eoeandroid.com/sdk/4.1/installer_r20-windows.exe Mac版: http://s1.eoeandroid.com/sdk/4.1/android-sdk_r20-macosx.zip ...
android最好的开机自启动项管理软件,软件暂用资源小,功能强大,绿色无广告~~极力推荐
在Android平台上实现应用的自启动功能。部分山寨机修改系统,可能会出现问题,