如何为Android双击创建服务?

时间:2013-11-10 06:09:34

标签: java android

您好我想创建一个服务,检测主屏幕上的双击我写下面的代码。不知怎的,它没有工作任何人告诉我代码有什么问题

public class TapService extends Service implements GestureDetector.OnDoubleTapListener {

     private GestureDetector gestureDetector;
    @Override
    public void onCreate()
    {
         gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener()); 
    }
    @Override
    public boolean onDoubleTap(MotionEvent arg0) {
        Log.w("Tap", "Double tap");
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

}

我的活动类..我没有在logcat中收到任何错误

public class TapActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tap);
        startService(new Intent(this, TapService.class));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.tap, menu);
        return true;
    }

}

0 个答案:

没有答案