App实现开机启动
Android启动时,会发出一个系统广播 ACTION_BOOT_COMPLETED,它的字符串常量表示为 “android.intent.action.BOOT_COMPLETED”
开机自启动程序,只需要“捕捉”到这个消息再启动你的程序即可,我们要做的是接收这个消息,并实现一个BroadcastReceiver。
1.添加一个自定义广播类 BootReceiver
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { // boot
Intent intent2 = new Intent(context, MainActivity.class);
// intent2.setAction("android.intent.action.MAIN");
// intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
}
2.在AndroidManifest.xml中Application节点内,添加自定义的广播类和权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.moumou.sharedpreferencetest">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> //权限
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BootReceiver" > //自定义广播类
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
</application>
</manifest>
App实现开机启动的更多相关文章
- chrome浏览器 配置开机启动全屏(看板app模式设置)
chrome浏览器 配置开机启动全屏(看板app模式设置) 1.下载安装chrome浏览器. 2.建立一个chrome浏览器的快键方式,右键打开属性,如下图: 3.将目标选项卡的值修改为:&q ...
- Android App 开机启动画面和开机自动启动APP程序设置
1.当前比较成熟一点的应用基本上都会在进入应用之显示一个启动界面 如腾讯微博 2.准备元素 需要开机启动的图片一张 3.新建Activity AlphaAnimation动画:控制对象alpha水平 ...
- <Android Studio> 2.APP开机启动
开机启动,也就是App随着机器开机而启动,在很多工业场景中是非常常见的. 开机启动的基本原理就是监听系统启动相关的广播,然后启动App. 为了实现开机启动,我人为的分为几个步骤 1.创建broadca ...
- WIN8,开机启动 需要管理员权限的程序
1. 用WPF开发,需要管理员权限并开机启动,以写注册表的方式实现.仅写注册表只能启动一般权限的程序. 2. 考虑这样实现: 程序以一般权限启动,启动以后申请管理员权限. 实现: App类中重写OnS ...
- Android开机启动Activity或者Service方法
本文出自 “Bill_Hoo专栏” 博客,请务必保留此出处http://billhoo.blog.51cto.com/2337751/761230 这段时间在做Android的基础开发,现在有一需求是 ...
- Android如何获取开机启动项列表
static final String BOOT_START_PERMISSION = "android.permission.RECEIVE_BOOT_COMPLETED"; p ...
- Android安全问题 抢先开机启动
导读:我们以如何抢先开机启动为例,来说明接收无序广播的静态广播接收器的接收顺序 (注意,文本只是陈述结果,所以叫结果篇,之后的文章再给出源码分析) 首先先说一下android中的广播和广播接收器 广播 ...
- android131 360 05 手势触摸滑动,sim卡,开机启动的广播,手机联系人,SharedPreferences,拦截短信
安卓手势触摸滑动: package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.con ...
- Android 开机启动通知
效果图: 学习: 1.静态注册实现开机启动 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLET ...
随机推荐
- /usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
https://stackoverflow.com/questions/39111930/usr-include-boost-python-detail-wrap-python-hpp5023-fat ...
- POI解析Excel文件
@Test public void test1() throws FileNotFoundException, IOException{ HSSFWorkbook workbook = new HSS ...
- (并查集 建立关系)食物链 -- POJ-- 1182
链接: http://poj.org/problem?id=1182 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- HashMap底层实现原理以及HashMap与HashTable区别以及HashMap与HashSet区别
①HashMap的工作原理 HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象.当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算h ...
- Spring MVC 的@RequestParam注解和request.getParameter("XXX")
在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...
- [leetcode] 18. Length of Last Word
这个题目很简单,给一个字符串,然后返回最后一个单词的长度就行.题目如下: Given a string s consists of upper/lower-case alphabets and emp ...
- spring的事务传播属性
一.Propagation (事务的传播属性) Propagation : key属性确定代理应该给哪个方法增加事务行为.这样的属性最重要的部份是传播行为.有以下选项可供使用:PROPAGATION_ ...
- SoapUI5.1.2安装和破解教程
一.SoapUI简介 soapui提供一个工具通过soap/http来检查,调用,实现web service和web service的功能/负载/符合性测试. 该工具既可作为一个桌面应用软件使用,也可 ...
- JEECG(二) JEECG框架下调用webservice java springmvc maven 调用 webservice
JEECG系列教程二 如何在JEECG框架下使用webservice 本文所使用的webservice是c#开发的 其实无论是什么语言开发的webservice用法都一样 java springmvc ...
- day 77 基于form组件的注册功能
Form 表单 py文件 from django import forms #定义一个form类注册用 class RegForm (forms.Form): username =forms.Char ...