BroadcastReceiver(广播接收器):发出广播让服务器去接收
BootReceiver.java
package com.example.chenshuai.test321;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log; public class BootReceiver extends BroadcastReceiver {
public BootReceiver() { Log.e("TAG","构造开机完成广播接收器");
} @Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
//throw new UnsupportedOperationException("Not yet implemented"); //启动服务
context.startService(new Intent(context,BootService.class)); Log.e("TAG", "广播接收器自动启动Service"); }
}
Service:接收广播传过来的意图
BootService.java
package com.example.chenshuai.test321;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log; public class BootService extends Service {
public BootService() {
} @Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
//throw new UnsupportedOperationException("Not yet implemented"); return null;
} @Override
public void onCreate() {
super.onCreate(); Log.e("TAG","服务自动启动了");
}
}

在manifest.xml中调至相同频率/同时设置权限

<!--接收开机完成的广播权限-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <service
android:name=".BootService"
android:enabled="true"
android:exported="true" /> <receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
 

Android——开机启动功能(Service和BroadcastReceiver)的更多相关文章

  1. Android开机启动Activity或者Service方法

    本文出自 “Bill_Hoo专栏” 博客,请务必保留此出处http://billhoo.blog.51cto.com/2337751/761230 这段时间在做Android的基础开发,现在有一需求是 ...

  2. Android开机启动Activity或者Service方法(转载)

    这段时间在做Android的基础开发,现在有一需求是开机启动,按照网上某些博文教程做了下,始终不成功,一开机总是提示所启动的应用程序意外终止,于是参考了Android SDK doc,终于解决问题,下 ...

  3. ANDROID 开机启动VNC SERVER

    ANDROID 开机启动VNC SERVER 背景信息: 最近在做一个项目,在项目需求中有这么一项“要把VNC SERVER 添加到android里并让其开机自启动”.其实做这个项目也挺缚手缚脚的,因 ...

  4. android开机启动流程说明

    android开机启动流程说明 第一步:启动linux 1.Bootloader 2.Kernel 第二步android系统启动:入口为init.rc(system\core\rootdir) 1./ ...

  5. Android如何配置init.rc中的开机启动进程(service)【转】

    本文转载自:http://blog.csdn.net/qq_28899635/article/details/56289063 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...

  6. Android -- 开机启动无界面后台程序

    简单的说,这是一个没有界面的后台运行的应用程序 而且,还有一功能:开机自启动,启动运行一个服务 程序结构非常简单,两个类,一个是service的扩展类,一个是BroadcastReceiver扩展类 ...

  7. Android开机启动程序

    android程序实现开机启动的原理,简单点说就是做一个广播接收器,接收到开机广播时就启动activity或service或执行其它操作.Android系统在启动的时候会发出一个开机广播,内容为ACT ...

  8. Android 开机启动

    创建一个Receiver,用来监听开机完毕: public class MyReceiver extends BroadcastReceiver { static final String actio ...

  9. Android 开机启动通知

    效果图: 学习: 1.静态注册实现开机启动 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLET ...

随机推荐

  1. PMD-Java 代码检查工具对 error 和 warning 的配置

    PMD是一款优秀的Java程序代码检查工具.该它可以检查Java代码中是否含有未使用的变量.是否含有空的抓取块.是否含有不必要的对象等. 但在使用过程中,你会项目中发现存在大量的 PMD 插件报出的 ...

  2. Linux中iptables防火墙指定端口范围

    我需要700至800之间的端口都能tcp访问 代码如下 复制代码 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 7 ...

  3. (面试)写出下面switch语句的输出结果

    (1) public static void main(String[] as) { int a = 0;  switch (a)  { case 1:   System.out.println(&q ...

  4. linux 压缩和解压命令

    Linux下的压缩解压缩命令详解及实例 实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip == ...

  5. git clone 问题 fatal: unable to access

    git clone 遇到问题 Cloning into 'warp-ctc'...fatal: unable to access 'https://github.com/SeanNaren/warp- ...

  6. python标准库介绍——34 commands 模块详解

    ==commands 模块== (只用于 Unix) ``commands`` 模块包含一些用于执行外部命令的函数. [Example 3-7 #eg-3-7] 展示了这个模块. ====Exampl ...

  7. Java代码通过API操作HBase的最佳实践

    HBase提供了丰富的API.这使得用Java连接HBase非常方便. 有时候大家会使用HTable table=new HTable(config,tablename);的方式来实例化一个HTabl ...

  8. thinkphp AOP(面向切面编程)钩子和行为

    在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的 ...

  9. 模态推出 全屏 隐藏tabbar

    SearchVC * vc = [[SearchVC alloc] init]; /* 底部向上  UIModalTransitionStyleCoverVertical // 淡入     UIMo ...

  10. 用Power BI观察经济与健康的关系

    Hans Rosling是卡罗琳学院的国际卫生学教授.这位学者与众不同的技能是数据可视化.以直观的数据展现了令人信服的世界观,而且在gapminder.org提供无偿展示以及下载.假设你没有看过下面的 ...