android开机app自启动
来源:互联网 发布:淘宝网违规处理一览表 编辑:程序博客网 时间:2024/04/20 20:52
开机的情况下,android系统会发出一个boot的广播,只需要定义一个broadcastReceiver,接收这个广播,启动相应的service或者activity即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package
com.app.broadcast;
import
com.app.boot.MainActivity;
import
android.content.BroadcastReceiver;
import
android.content.Context;
import
android.content.Intent;
import
android.util.Log;
import
android.widget.Toast;
public
class
BootBroadcast
extends
BroadcastReceiver {
static
final
String action_boot =
"android.intent.action.BOOT_COMPLETED"
;
@Override
public
void
onReceive(Context context, Intent intent) {
if
(intent.getAction().equals(action_boot)) {
// 1.启动自己app里面的activity
Intent myIntent1 =
new
Intent(context, MainActivity.
class
);
myIntent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent1);
// 2.启动其他app里面的activity或者service
Intent myIntent2 = context.getPackageManager()
.getLaunchIntentForPackage(
"com.example.usageslidingmenu"
);
myIntent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent2);
}
}
}
androidmanifest.xml:
1
2
3
4
5
6
<
receiver
android:name
=
"com.app.broadcast.BootBroadcast"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.BOOT_COMPLETED"
/>
<
category
android:name
=
"android.intent.category.HOME"
/>
</
intent-filter
>
</
receiver
>
添加权限:
1
<
uses-permission
android:name
=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
0 0
- android开机app自启动
- android开机自启动app
- android开机自启动app
- Android 实现开机自启动app
- Android开机自启动App(附带源码)
- android开机自启动app示例分享
- Android设置App是否开机自启动
- android总结一: 开机自启动APP
- Android开发 设置App开机自启动
- Android 代码设置开机自启动App
- android的APP开机自启动
- app开机自启动
- APP开机自启动
- APP开机自启动
- App开机自启动
- 开机后自启动app
- Android开机自启动
- Android开机自启动。
- IOS视频压缩
- git 的一些使用命令
- Android RecycleView(一)
- thinkphp 在 nginx 中配置 (rewrite)
- 第十三章 RememberMe——《跟我学Shiro》
- android开机app自启动
- Android HandlerThread 解析
- LeetCode #260 Single Number III
- 解决 Caused by: android.view.InflateException: Binary XML file line #57: Error inflating class fragmen
- Javascript的对象操作 - 数组元素操作 【javascript、数组、插入、删除、替换】 ( 咋个办呢 -zgbn)
- maven 将jar包导出到main\webapp\WEB-INF\lib文件下
- angular中的显示与隐藏ng-show/ng-hide/ng-if/ng-switch
- 文本分析之TFIDF/LDA/Word2vec实践
- 科普篇