Android--一个好玩的应用程序/开机自启动
2013-02-04 21:37
225 查看
这个例子实现了一个小程序,这个程序的特殊之处在于只要运行一次,然后它就会伴随着手机的启动而自己运行。
首先,为了捕捉手机启动的事件,我们需要在AndroidManifest.xml文件中添加如下的代码:
其中:
这行代码是接收系统发送的广播事件。
下面给出这个程序的完整代码:
1.主程序的代码
这段代码其实就是提供一个Activity UI界面,不负责接收系统广播
2.广播接收器
首先,为了捕捉手机启动的事件,我们需要在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--一个好玩的应用程序/开机自启动
- Android在开机时自动启动一个应用程序
- android7.1增加一个开机自启动的bin应用遇到的权限问题
- 如何让android应用程序只在factory reset后开机自启动
- android 开机自启动一个service
- android实现应用程序的开机自启动
- android实现应用程序的开机自启动
- Android应用程序显示欢迎画面并开机自启动
- android 开机自启动应用程序
- android 应用程序实现开机自启动
- Android在开机时自动启动一个应用程序
- Android之应用程序监听开机启动自启动应用程序
- Android在开机时自动启动一个应用程序
- Android——监听开机启动,自启动应用程序
- Android在开机时自动启动一个应用程序
- 创建一个开机自启动的Android系统服务
- Android开发之实现应用程序的开机自启动
- android 开机自启动一个activity
- Android实现开机自启动(二)——启动一个activity
- 如何让Android应用程序只在factory reset后开机自启动