1

我需要让我的闹钟在我的设备被锁定时唤醒我的设备我如何让这个闹钟在我的设备被锁定时唤醒我的设备,我尝试了很多代码但它不起作用,

这是我的代码

// Alert Code
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("confirmation");
    alertDialog.setMessage("r u sure u wanna send it");

    // Timer Code
    pendingIntent = PendingIntent.getService(CreateNewForm_3.this, 0,
            new Intent(CreateNewForm_3.this, MyAlarmService.class), 0);
    Send.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            alertDialog.setButton("yes",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            // -1- InshaAllah we've to send the Case info.
                            // here MMS
                            String FullCaseMsg = "name: " + case1.getName() + "$"
                                    + " gender: " + case1.getGender() + "$"
                                    + " Age: " + case1.getAge() + "$"
                                    + " clothes: " + case1.getClothes()
                                    + "$" + " MoreInfo: "
                                    + case1.getMoreInfo() + "$" + " time: "
                                    + case1.getTime() + "$" + " loc: "
                                    + case1.getLocation() + "$";
                            // -2- then show toast
                            Toast.makeText(CreateNewForm_3.this, "sent ", 0)
                                    .show();
                            // test

                            // -3- starting timer
                            long firstTime = SystemClock.elapsedRealtime();
                            am = (AlarmManager) getSystemService(ALARM_SERVICE);
                            am.setRepeating(
                                    AlarmManager.ELAPSED_REALTIME_WAKEUP,
                                    firstTime + 10 * 1000, 30 * 1000,
                                    pendingIntent);
                            // firstTime Will be the current_time + ( 10 *
                            // 60 * 1000) =)
                            // 10* 1000 will be (10 * 60 * 1000)
                            new Handler().postDelayed(new Runnable() {
                                public void run() {
                                    bCancel.performClick();
                                }
                            }, (30 * 1000));
                            // ( 30 * 1000) will be firstTime + ( 2-
                            // duration)

                            /*Intent toRecentCases = new Intent(
                                    CreateNewForm_3.this, LMPActivity.class);
                            startActivity(toRecentCases);*/


                            //4-add my case object to list View
                         //All_Static.MyCaseList.add(case1);




                        }
                    });

            alertDialog.setButton2("no",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            // here you can add functions

                        }
                    });

            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
            alertDialog.show();
        }

    });

    bCancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            am.cancel(pendingIntent);
        }
    });

任何帮助将不胜感激提前谢谢

4

1 回答 1

0

“AlarmManager.ELAPSED_REALTIME_WAKEUP”确实会在设备关闭时唤醒设备,但我认为没有机会“解锁”(引脚或模式?)设备,因为这将是一个安全问题。(如我错了请纠正我...)。

于 2012-04-23T15:27:29.243 回答