首先是 am.set(AlarmManager.RTC_WAKEUP, time, sendar),设置一个可以唤醒机器的Broadcast。
在Broadcast的onReceive里面调用 sCpuWakeLock.acquire()唤醒机器,
然后Intent i = new Intent(context, main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(intent);
在main的onCreate里面
super.onCreate(savedInstanceState);
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.main);
main的xml属性
<activity
android:name=".main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.CustomDialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation" />
现在能唤醒机器,但是main不能出现在锁屏画面的前面。
解决方案
将main的theme改成
android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
就可以了
在Broadcast的onReceive里面调用 sCpuWakeLock.acquire()唤醒机器,
然后Intent i = new Intent(context, main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(intent);
在main的onCreate里面
super.onCreate(savedInstanceState);
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.main);
main的xml属性
<activity
android:name=".main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.CustomDialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation" />
现在能唤醒机器,但是main不能出现在锁屏画面的前面。
解决方案
将main的theme改成
android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
就可以了