2009-11-26 8 views
0

Roger,Intentions de caméra Android

Je constate que vous avez bricolé avec les intentions de l'appareil photo. J'ai de la difficulté à obtenir une application simple pour me dire quand le bouton de la caméra a été pressé. Avez-vous du code pour m'aider sur mon chemin.

Merci.

David

Répondre

3

Dans le manifeste, vous devez vous dire souhaitez recevoir l'intention du bouton de la caméra:

<receiver android:name="domain.namespace.CameraReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.CAMERA_BUTTON"/> 
     </intent-filter> 
    </receiver> 
    <activity android:name="domain.namespace.MyCameraActivity" 
      android:label="@string/app_name" android:screenOrientation="landscape" android:icon="@drawable/camera" 
     android:clearTaskOnLaunch="true"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    <intent-filter> 
      <action android:name="android.media.action.IMAGE_CAPTURE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
    </activity> 

Dans le récepteur:

public void onReceive(Context context, Intent intent) { 
    KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 

    if (event == null) { 
    return; 
    } 

    //prevent the camera app from opening 
    abortBroadcast();  

    Intent i = new Intent(Intent.ACTION_MAIN); 
    i.setClass(context, MyCameraActivity.class); 
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(i);  
} 
Questions connexes