Show Alertdialog and use vibrator

Posted by user1007522 on Stack Overflow See other posts from Stack Overflow or by user1007522
Published on 2013-10-22T09:36:09Z Indexed on 2013/10/22 9:54 UTC
Read the original article Hit count: 255

I'm having a class that implements RecognitionListener like this:

public class listener implements RecognitionListener

I wanted to show a alertdialog and use the vibrator but this isn't possible because I need to provide a context what I don't have.

My alertdialog code was like this:

    new AlertDialog.Builder(this)
        .setTitle("dd")
        .setMessage("aa")
        .setNeutralButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 

            }
         })
         .show();

But the AlertDialog.Builder(this) wants a context, the same problem with my vibrator code:

v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

The getSystemService method isn't available.

My code that starts the class:

sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");

intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); 
sr.startListening(intent);

Whats the best way to solve this?

© Stack Overflow or respective owner

Related posts about android

Related posts about android-alertdialog