2011-06-09 74 views
3

我開發了一個有趣的應用程序,但有一些淘氣的人是通過使用不同類型的屏幕腳輪肆意破壞其他人的樂趣,然後自動播放腳本和欺騙用戶。如何檢測屏幕腳輪android,檢測敲擊壓力

here is a link到一個非常有名的屏幕施法者。但有什麼方法可以檢測到它?我想我已經讀過一些地方,我可以在Android中獲取加速度計的敲擊壓力。

請幫助

+0

http://developer.android.com/reference/android/view/MotionEvent.html#getPressure(int) – 2011-06-09 13:20:07

+0

你可以去聯繫,有是MotionEvent檢測壓力的方法,但沒有嘗試過。 – 2011-06-09 13:20:36

+0

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html一個關於但不完全是我想要的例子 – 2011-06-09 13:30:37

回答

1

示例應用程序

package com.pressure.detection; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.view.View; 
import android.widget.TextView; 

public class StartActivity extends Activity implements View.OnTouchListener { 
    /** Called when the activity is first created. */ 

private TextView tvConsole; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
findViewById(R.id.root_layout).setOnTouchListener(this); 

tvConsole = (TextView)findViewById(R.id.txtConsole); 
    } 

    @Override 
    public boolean onTouch(View view, MotionEvent mEvent) { 
    tvConsole.setText("Pressure: "+mEvent.getPressure()); 


System.out.println("Hardware X " + mEvent.getXPrecision() 
    * mEvent.getX()); 
System.out.println("Hardware Y " + mEvent.getYPrecision() 
    * mEvent.getY()); 
return super.onTouchEvent(mEvent); 
    } 

}