receiver定制自动启动一个程序
16lz
2021-01-26
意思就是当手机系统启动完毕后,立即启动我们定制的应用:
android 有一个系统Broadcast 其action = "android.intent.action.BOOT_COMPLETED" 用途就是通知系统已经启动完毕.我们的做法就是创建一个BroadcastReceiver 用来接收该Broadcast 在收到以后通过startActivity / startService 来启动目标应用
直接上代码把:
1.AndroidManifest.xml文件
2. SystemUpApp.java文件
3. UpNotificationListener.java文件
4.main.xml文件
android 有一个系统Broadcast 其action = "android.intent.action.BOOT_COMPLETED" 用途就是通知系统已经启动完毕.我们的做法就是创建一个BroadcastReceiver 用来接收该Broadcast 在收到以后通过startActivity / startService 来启动目标应用
直接上代码把:
1.AndroidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.com" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".SystemUpApp" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity><receiver android:name="UpNotificationListener" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> </application> <uses-sdk android:minSdkVersion="2" /></manifest>
2. SystemUpApp.java文件
package cn.com;import android.app.Activity;import android.os.Bundle;public class SystemUpApp extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
3. UpNotificationListener.java文件
package com.android.AppSystemUp;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;public class UpNotificationListener extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubIntent i = new Intent(context, SystemUpApp.class);i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(i);}}
4.main.xml文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView android:id="@+id/text" android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="Start After the System launch Completely"android:layout_centerInParent="true" android:ellipsize="marquee" /></RelativeLayout>
更多相关文章
- Ubuntu13.04环境下载、编译Android源代码
- node.js+android(使用HttpURLConnection和HttpClient)实现文件上
- [cocos2dx] cocosdx编译工程那些事
- Android(安卓)SDK API 13升级指南
- Android视频播放框架一、Vitamio
- android aidl 传递parcelable
- JNI综合实验一:LED点亮+IO电平读取
- View编程(5): 自定义View_01_ApiDemo源码研究
- 简单实现Android文件上传