|
【Android】
程序设置的有开机自启动,但是没有生效
发表于 2020-10-20 09:45:16
浏览:6107
|
回复:0
打印
只看该作者
[复制链接]
楼主
通过Android的开机广播设置的开机自启动但是没有生效
W* k( { L; O. C4 l4 t+ j; a3 Y" N! ?; q0 f$ j/ u% c' g
public class BootBroadcastReceiver extends BroadcastReceiver {% ~8 p6 j$ \. L) _' J
+ d* v5 {' m- n9 W* d7 b @Override9 ]! E' N B! ]; E+ _6 g& {) S
public void onReceive(final Context context, Intent intent) {
1 B# R' Y; Z$ q& | new Thread(new Runnable() {% w* ]" b& t8 B9 T
@Override
. z) I0 I+ S; ~7 x) o public void run() {
( w' l% g9 e& | Y2 H try {
7 j; T3 Z( m- |, F$ Q Thread.sleep(1000 * 30);
& p6 m* ~! L% Q- z+ T5 a5 U Intent bootIntent = context.getPackageManager().getLaunchIntentForPackage("com.dnt.infraredshelf"); z! t: j% p. A
context.startActivity(bootIntent);
& l1 o; j! a2 ]3 ?9 \0 L# B: R) m } catch (InterruptedException e) {
1 c* C9 S3 \& ?; m3 a e.printStackTrace();4 U# q3 c/ R* i6 Z4 e
} X. C/ l" V8 l! y, E9 ^* F5 M
}2 w' J$ l8 {1 @' @
}).start();% d, w9 X; e' K; _4 j
}
4 \7 B$ v4 F% O, _( n( z}* w0 v- {0 u9 U' S
|
|