转:android中APK开机自动运行
package com.ghstudio.BootStartDemo; import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView; public class SayHello extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); TextView tv = new TextView(this);
tv.setText("Hello. I started!"); setContentView(tv);
}
}
package com.ghstudio.BootStartDemo; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; public class BootBroadcastReceiver extends BroadcastReceiver { static final String ACTION = "android.intent.action.BOOT_COMPLETED"; @Override
public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION)){
Intent sayHelloIntent=new Intent(context,SayHello.class);
sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(sayHelloIntent);
}
} }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ghstudio.BootStartDemo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SayHello"
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=".BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> </manifest>
===========================================
1.要做的就是监听系统发出的broadcast
public class FlorenceText extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
start(context);
}
}
}
2.在AndroidMenifest.xml里还要将receiver加上, 并写明程序的入口就是FlorenceTest
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".main.FlorenceTest"
android:exported="true"
android:process=":remote"> <intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver> </application>
这样,程序就可以在开机时自动运行了
转自:http://blog.csdn.net/wh_19910525/article/details/7921685
转:android中APK开机自动运行的更多相关文章
- [转载] 在Linux中,开机自动运行普通用户的脚本程序
FROM:http://blog.csdn.net/sinboy/article/details/2466225 FROM:http://www.2cto.com/os/201006/50680.ht ...
- Android---让你的APK程序开机自动运行(转)
转自: http://blog.sina.com.cn/s/blog_72f6e45701014l6t.html 有些时候,应用需要在开机时就自动运行,例如某个自动从网上更新内容的后台service. ...
- 【转】]Android实现开机自动运行程序
有些时候,应用需要在开机时就自动运行,例如某个自动从网上更新内容的后台service.怎样实现开机自动运行的应用?在撰写本文时,联想到高焕堂先生以“Don't call me, I'll call y ...
- Android实现开机自动运行程序
有些时候,应用需要在开机时就自动运行,例如某个自动从网上更新内容的后台service.怎样实现开机自动运行的应用?在撰写本文时,联想到高焕堂先生以“Don't call me, I'll call y ...
- Android开机自动运行APP——BroadcastReceiver
前言: 有些时候,应用需要在开机时就自动运行,例如某个自动从网上更新内容的后台service.怎样实现开机自动运行的应用?在撰写本文时,联想到高焕堂先生以“Don't call me, I'll ca ...
- C#.NET Form设置/取消开机自动运行,判断程序是否已经设置成开机自动启动(转载)
#region//开机自动运行 private void CB_Auto_CheckedChanged(object sender, EventArgs e) {//CB_ ...
- C# 设置程序开机自动运行(+注册表项)
有时候我们需要让软件安装好了,开机自动运行,这时我们需要把启动项加载到注册表中,需要注意的时现在很多杀毒软件在其他软件更改注册表的时候会有提示,可能会阻止.下面代码包含增加启动项到注册表和删除启动项. ...
- C#安装程序制作让安装后的程序开机自动运行
1.创建安装项目后要在自己的解决方案是添加一个新的类库项目(ClassLibrary1),并在新类库中添加一下安装程序类(Installer1),在Installer1类中添加如下代码: string ...
- /etc/rc.local 与 /etc/init.d Linux 开机自动运行程序
1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里 --------引用---------------------- 在完成 run level 3 ...
随机推荐
- git 初级
以前工作中用到git,但没有总结,这次借鉴其它博客加上自己实践,总结git的简单用法 首先安装.... 打开一个文件右击git bash 弹出来一个jit界面 git config http.post ...
- windows 下安装elasticsearch
1.下载 elasticsearch-2.3.3.zip 注意::elasticsearch 版本太高的话,java运行不起来 elasticsearch-1.5.2下载地址 http://downl ...
- 在COM接口中不要使用同时出现只是大小写不同的名字作为属性名、函数名或者参数名
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:在COM接口中不要使用同时出现只是大小写不同的名字作为属性名.函数名或者参数名.
- spring的有状态BEAN和无状态BEAN
有状态会话bean :每个用户有自己特有的一个实例,在用户的生存期内,bean保持了用户的信息,即“有状态”:一旦用户灭亡(调用结束或实例结束),bean的生命期也告结束.即每个用户最初都会得到一 ...
- os4开始CLLocationManager类中不支持locationServicesEnabled属性了
locationServicesEnabled改为类方法 //判断定位服务是否开启 if ([CLLocationManager locationServicesEnabled]) { }
- 多平台响应键盘事件!(适用于Cocos2dx 3.0 alpha以上版本号)
Hello everyone! For a week I've been looking on how to make a keyboard work! I managed to figure it ...
- MongoDB的地埋空间数据存储、空间索引以及空间查询
一.关于MongoDB 在众多NoSQL数据库,MongoDB是一个优秀的产品.其官方介绍如下: MongoDB (from "humongous") is a scalable, ...
- MVC架构杂谈
来源:伯乐在线专栏作者 - 林欣达 链接:http://ios.jobbole.com/86895/ 点击 → 了解如何加入专栏作者 前言 MVC是软件工程中的一种软件架构模式,它把软件系统分为三个基 ...
- Socket解决粘包问题2
在AsynServer中对接收函数增加接收判断,如果收到客户端发送的请求信息,则发送10个测试包给发送端,否则继续接收,修改后的接收代码如下: private void AsynReceive() { ...
- html笔记04:在html之中导入css两种常见方法
1.导入式: <html> <head> <title></title> <style type="text/css"> ...