我创建了一个程序,即使手机被锁定,它也会在收到消息时发出警报。当电话响起时,它会显示关闭按钮以停止闹钟,但我的代码只显示关闭按钮并迅速消失,让我无法选择如何停止闹钟。请帮我处理这段代码。提前感谢您的帮助
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.receiverinterface);
unlockScreen();
alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setTitle("Alarm");
alertDialogBuilder
.setMessage("Stop Alarm")
.setCancelable(false)
.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
Ringtone r = EAlarmReceiver.r;
r.stop();
Toast.makeText(context.getApplicationContext(), "Alarm Stopped", Toast.LENGTH_LONG).show();
if(EAlarmReceiver.sms.length() > 10)
{
Intent openInterface = new Intent("proj.receiver.VIEWMESSAGE");
openInterface.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openInterface);
}
else
{
Intent openInterface = new Intent("proj.receiver.RECEIVERINTERFACE");
openInterface.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openInterface);
}
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}// end oncreate()
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
//unlock screen
public void unlockScreen() {
//make the activity show even the screen is locked.
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
+ WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}