Android 如何使语音识别器在全屏幕上工作

Android 如何使语音识别器在全屏幕上工作,android,speech-recognition,ontouchlistener,Android,Speech Recognition,Ontouchlistener,我正在为视障人士制作一个应用程序,为此,我希望每当用户触摸屏幕上的任何地方时,语音识别器都应该启动 我做过语音识别器和其他东西…但我不能让我的语音识别器在TouchListener上工作 TouchListener未将活动作为视图。应用程序崩溃 完整代码如下所示 public class MainActivity extends Activity { private static final int REQUEST_CODE = 1234; private ListView wordsList

我正在为视障人士制作一个应用程序,为此,我希望每当用户触摸屏幕上的任何地方时,语音识别器都应该启动

我做过语音识别器和其他东西…但我不能让我的语音识别器在TouchListener上工作

TouchListener未将活动作为视图。应用程序崩溃

完整代码如下所示

public class MainActivity extends Activity
{

private static final int REQUEST_CODE = 1234;
private ListView wordsList;
protected Button TextToSpeech;
/**
 * Called with the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
setContentView(R.layout.voice_recog);
Button speakButton = (Button) findViewById(R.id.speakButton);
Context context;
context = this.getApplicationContext();
Intent Inte = new Intent(context, FallDetection.class);
context.startService(Inte);
Intent Inte1 = new Intent(context, SmsSpeaker.class);
context.startService(Inte1);
Toast toast = Toast.makeText(getApplicationContext(), "Fall Detection Started", Toast.LENGTH_LONG);
toast.show();

 wordsList = (ListView) findViewById(R.id.list);
 LinearLayout myScreen = (LinearLayout) findViewById(R.id.myscreen); 
// change LinearLayout to your framelayout if it is not a LinearLayout
//View view =(View) findViewById(R.layout.voice_recog);

//wordsList.setOnTouchListener(new View.OnTouchListener() {
 myScreen.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast toast = Toast.makeText(getApplicationContext(),"Touch recognised",Toast.LENGTH_LONG);
        toast.show();
        startVoiceRecognitionActivity();
    }
}); 
到目前为止,我正在使用列表来识别触摸,但这也导致应用程序崩溃,源代码未找到异常

布局xml文件如下所示

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/myscreen" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical">

布局xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  
xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/myscreen"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dip"
android:text="Click the button and start speaking" />

<Button android:id="@+id/speakButton"
android:layout_width="fill_parent"
android:onClick="speakButtonClicked"
android:layout_height="wrap_content"
android:text="Click Me!" />
<ScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.41" >
</ListView>
</ScrollView>
</LinearLayout>

你的词表是干什么的?您是否设置了McClickListener?单词列表将存储语音识别器的结果..口语单词的可能匹配项。。。。。。。。。。。。不,不,我编辑了我的答案,在我的应用程序中,我做了一次点击,结果成功了。您还应该请求全屏显示,将这些内容放在setContenView()requestWindowFeature(Window.FEATURE\u NO\u TITLE)上方的行上;getWindow().addFlags(WindowManager.LayoutParams.FLAG\u保持屏幕打开);thanx Hoan…我按照你说的做了…但它给出了错误,因为类型视图中的方法setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){}),我认为你导入的错误应该是导入android.View.View.OnClickListener;不,只是导入了…但它无法识别触摸。你是否删除了TouchListener上的worldlist?
public class MainActivity extends Activity
{

    private static final int REQUEST_CODE = 1234;
    private ListView wordsList;
    protected Button TextToSpeech;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.voice_recog);
        Button speakButton = (Button) findViewById(R.id.speakButton);

        Intent Inte = new Intent(this, FallDetection.class);
         startService(Inte);
        Intent Inte1 = new Intent(this, SmsSpeaker.class);
        startService(Inte1);
        Toast toast = Toast.makeText(this, "Fall Detection Started", Toast.LENGTH_LONG);
        toast.show();

        wordsList = (ListView) findViewById(R.id.list);
        LinearLayout myScreen = (LinearLayout) findViewById(R.id.myscreen); 

        myScreen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
    // TODO Auto-generated method stub
          Toast toast = Toast.makeText(MainActivity.this,"Touch recognised",Toast.LENGTH_LONG);
         toast.show();
         startVoiceRecognitionActivity();
    }
  }); 
}