VoiceInteractionService.java revision 18f0d357f9693fe787a3e3777d8fdf01357a6e3f
1/** 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.service.voice; 18 19import android.annotation.SdkConstant; 20import android.app.Instrumentation; 21import android.app.Service; 22import android.content.Context; 23import android.content.Intent; 24import android.os.Bundle; 25import android.os.IBinder; 26import android.os.RemoteException; 27import android.os.ServiceManager; 28import com.android.internal.app.IVoiceInteractionManagerService; 29 30public class VoiceInteractionService extends Service { 31 /** 32 * The {@link Intent} that must be declared as handled by the service. 33 * To be supported, the service must also require the 34 * {@link android.Manifest.permission#BIND_VOICE_INTERACTION} permission so 35 * that other applications can not abuse it. 36 */ 37 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) 38 public static final String SERVICE_INTERFACE = 39 "android.service.voice.VoiceInteractionService"; 40 41 /** 42 * Name under which a VoiceInteractionService component publishes information about itself. 43 * This meta-data should reference an XML resource containing a 44 * <code><{@link 45 * android.R.styleable#VoiceInteractionService voice-interaction-service}></code> tag. 46 */ 47 public static final String SERVICE_META_DATA = "android.voice_interaction"; 48 49 IVoiceInteractionService mInterface = new IVoiceInteractionService.Stub() { 50 }; 51 52 IVoiceInteractionManagerService mSystemService; 53 54 public void startVoiceActivity(Intent intent, Bundle sessionArgs) { 55 try { 56 mSystemService.startVoiceActivity(intent, 57 intent.resolveType(getContentResolver()), 58 mInterface, sessionArgs); 59 } catch (RemoteException e) { 60 } 61 } 62 63 @Override 64 public void onCreate() { 65 super.onCreate(); 66 mSystemService = IVoiceInteractionManagerService.Stub.asInterface( 67 ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE)); 68 } 69 70 @Override 71 public IBinder onBind(Intent intent) { 72 if (SERVICE_INTERFACE.equals(intent.getAction())) { 73 return mInterface.asBinder(); 74 } 75 return null; 76 } 77} 78