锁定屏幕上摇

时间:2013-01-15 04:38:03

标签: android

我想在手机摇晃的情况下锁定屏幕,我已经创建了摇晃的听众,并且检测到手机发抖 代码是..

 Receiver myReceiver;
 Context context1;

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Vibrator vibe = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

    mShaker = new ShakeListener(this);
    mShaker.setOnShakeListener(new ShakeListener.OnShakeListener () {
      public void onShake()
      {

        vibe.vibrate(100);
        new AlertDialog.Builder(MainActivity.this)
          .setPositiveButton(android.R.string.ok, null)
          .setMessage("Shooken!")
          .show();

       PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);

        // Choice 1
 //         manager.goToSleep(amountOfTime);

// Choice 2
    PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Your Tag");
        wl.acquire();
        wl.release();



                }

    });
  }

  @Override
  public void onResume()
  {
    mShaker.resume();
    super.onResume();
  }
  @Override
  public void onPause()
  {
    mShaker.pause();
    super.onPause();
  }
}

警告对话框在那里,但它没有锁定手机我该怎么办

0 个答案:

没有答案