Fields Summary |
---|
public static final String | SERVICE_INTERFACEThe {@link Intent} that must be declared as handled by the service. |
public static final String | SERVICE_META_DATAName under which a RecognitionService component publishes information about itself.
This meta-data should reference an XML resource containing a
<{@link android.R.styleable#RecognitionService recognition-service}> tag. |
private static final String | TAGLog messages identifier |
private static final boolean | DBGDebugging flag |
private RecognitionServiceBinder | mBinderBinder of the recognition service |
private Callback | mCurrentCallbackThe current callback of an application that invoked the
{@link RecognitionService#onStartListening(Intent, Callback)} method |
private static final int | MSG_START_LISTENING |
private static final int | MSG_STOP_LISTENING |
private static final int | MSG_CANCEL |
private static final int | MSG_RESET |
private final android.os.Handler | mHandler |
Methods Summary |
---|
private boolean | checkPermissions(IRecognitionListener listener)Checks whether the caller has sufficient permissions
if (DBG) Log.d(TAG, "checkPermissions");
if (RecognitionService.this.checkCallingOrSelfPermission(android.Manifest.permission.
RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
return true;
}
try {
Log.e(TAG, "call for recognition service without RECORD_AUDIO permissions");
listener.onError(SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS);
} catch (RemoteException re) {
Log.e(TAG, "sending ERROR_INSUFFICIENT_PERMISSIONS message failed", re);
}
return false;
|
private void | dispatchCancel(IRecognitionListener listener)
if (mCurrentCallback == null) {
if (DBG) Log.d(TAG, "cancel called with no preceding startListening - ignoring");
} else if (mCurrentCallback.mListener.asBinder() != listener.asBinder()) {
Log.w(TAG, "cancel called by client who did not call startListening - ignoring");
} else { // the correct state
RecognitionService.this.onCancel(mCurrentCallback);
mCurrentCallback = null;
if (DBG) Log.d(TAG, "canceling - setting mCurrentCallback to null");
}
|
private void | dispatchClearCallback()
mCurrentCallback = null;
|
private void | dispatchStartListening(android.content.Intent intent, IRecognitionListener listener)
if (mCurrentCallback == null) {
if (DBG) Log.d(TAG, "created new mCurrentCallback, listener = " + listener.asBinder());
try {
listener.asBinder().linkToDeath(new IBinder.DeathRecipient() {
@Override
public void binderDied() {
mHandler.sendMessage(mHandler.obtainMessage(MSG_CANCEL, listener));
}
}, 0);
} catch (RemoteException re) {
Log.e(TAG, "dead listener on startListening");
return;
}
mCurrentCallback = new Callback(listener);
RecognitionService.this.onStartListening(intent, mCurrentCallback);
} else {
try {
listener.onError(SpeechRecognizer.ERROR_RECOGNIZER_BUSY);
} catch (RemoteException e) {
Log.d(TAG, "onError call from startListening failed");
}
Log.i(TAG, "concurrent startListening received - ignoring this call");
}
|
private void | dispatchStopListening(IRecognitionListener listener)
try {
if (mCurrentCallback == null) {
listener.onError(SpeechRecognizer.ERROR_CLIENT);
Log.w(TAG, "stopListening called with no preceding startListening - ignoring");
} else if (mCurrentCallback.mListener.asBinder() != listener.asBinder()) {
listener.onError(SpeechRecognizer.ERROR_RECOGNIZER_BUSY);
Log.w(TAG, "stopListening called by other caller than startListening - ignoring");
} else { // the correct state
RecognitionService.this.onStopListening(mCurrentCallback);
}
} catch (RemoteException e) { // occurs if onError fails
Log.d(TAG, "onError call from stopListening failed");
}
|
public final android.os.IBinder | onBind(android.content.Intent intent)
if (DBG) Log.d(TAG, "onBind, intent=" + intent);
return mBinder;
|
protected abstract void | onCancel(android.speech.RecognitionService$Callback listener)Notifies the service that it should cancel the speech recognition.
|
public void | onDestroy()
if (DBG) Log.d(TAG, "onDestroy");
mCurrentCallback = null;
mBinder.clearReference();
super.onDestroy();
|
protected abstract void | onStartListening(android.content.Intent recognizerIntent, android.speech.RecognitionService$Callback listener)Notifies the service that it should start listening for speech.
|
protected abstract void | onStopListening(android.speech.RecognitionService$Callback listener)Notifies the service that it should stop listening for speech. Speech captured so far should
be recognized as if the user had stopped speaking at this point. This method is only called
if the application calls it explicitly.
|