2009-11-26 98 views
0

罗杰,安卓相机意图

我看到你一直在修补相机意图。我有一个真正的麻烦,只是让 一个简单的应用程序告诉我什么时候按下了相机按钮。你有没有一些代码可以帮助我。

谢谢。

大卫

回答

3

在清单中,你需要说明你想收到拍照键的意图:

<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> 

在接收器:

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);  
}