广播接收器方式启动Camera
<application android:icon="@mipmap/ic_launcher_camera"
android:name="com.android.camera.CameraAppImpl"
android:label="@string/camera_label"
android:theme="@style/ThemeCamera"
android:hardwareAccelerated="true">
...
<receiver android:name="com.android.camera.CameraButtonIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.CAMERA_BUTTON"/>
</intent-filter>
</receiver>
...
</application>
public class CameraButtonIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
...
}
}
CameraHolder类中使用单例模式
public class CameraHolder {
// Use a singleton.
private static CameraHolder sHolder;
public static synchronized CameraHolder instance() {
if (sHolder == null) {
sHolder = new CameraHolder();
}
return sHolder;
}
使用SharedPreferences保存Camera的一些信息