摇动设备以启动应用程序

Sun*_*Sun 6 java android shake

我正在使用与Shake一起工作,这对我来说很好,但我想在用户摇动他们的设备时启动应用程序,请参阅下面的代码:

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

    transcript=(TextView)findViewById(R.id.transcript);
    scroll=(ScrollView)findViewById(R.id.scroll);

    shaker=new Shaker(this, 1.25d, 500, this);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();

    shaker.close();
  }

  public void shakingStarted() {
    Log.d("ShakerDemo", "Shaking started!");
    transcript.setText(transcript.getText().toString()+"Shaking started\n");
    scroll.fullScroll(View.FOCUS_DOWN);
  }

  public void shakingStopped() {
    Log.d("ShakerDemo", "Shaking stopped!");
    transcript.setText(transcript.getText().toString()+"Shaking stopped\n");
    scroll.fullScroll(View.FOCUS_DOWN);
  }
Run Code Online (Sandbox Code Playgroud)

所以这是我的问题,如何通过摇动我的设备启动应用程序?

Nit*_*ael 1

您需要编写代码,以便在摇动开始时将应用程序从后台启动到前台。此链接将帮助您做到这一点。