使用SharedPreferences设置摄像头默认像素
package com.android.camera;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera.CameraInfo;
import android.util.Log;
import android.content.SharedPreferences;
import android.os.SystemProperties;
// We want to disable camera-related activities if there is no camera. This
// receiver runs when BOOT_COMPLETED intent is received. After running once
// this receiver will be disabled, so it will not run again.
public class ResetCameraSettingsReceiver extends BroadcastReceiver {
private ComboPreferences mPreferences;
String str_16M = "1280x960";
String str_20M = "1600x1200";
String str_24M = "2560x1920";
@Override
public void onReceive(Context context, Intent intent) {
mPreferences = new ComboPreferences(context);
if(SystemProperties.get("persist.sys.selcusanim").equals("27")) {
SharedPreferences cameraPref = mPreferences.getSharedPreference(context, 0);
SharedPreferences.Editor editor = cameraPref.edit();
editor.putString("pref_camera_picturesize_ratio_key", "1.3333");
editor.putString("pref_camera_picturesize_key", str_16M);
editor.apply();
SharedPreferences cameraPref1 = mPreferences.getSharedPreference(context, 1);
SharedPreferences.Editor editor1 = cameraPref1.edit();
editor1.putString("pref_camera_picturesize_ratio_key", "1.3333");
editor1.putString("pref_camera_picturesize_key", str_20M);
editor1.apply();
} else {
SharedPreferences cameraPref = mPreferences.getSharedPreference(context, 0);
SharedPreferences.Editor editor = cameraPref.edit();
editor.putString("pref_camera_picturesize_ratio_key", "1.3333");
editor.putString("pref_camera_picturesize_key", str_20M);
editor.apply();
SharedPreferences cameraPref1 = mPreferences.getSharedPreference(context, 1);
SharedPreferences.Editor editor1 = cameraPref1.edit();
editor1.putString("pref_camera_picturesize_ratio_key", "1.3333");
editor1.putString("pref_camera_picturesize_key", str_24M);
editor1.apply();
}
}
}
2.读取SharedPreferences中的值
SharedPreferences cameraPref1 = mPreferences.getSharedPreference(context, 1);
String ratio=cameraPref1.getString("pref_camera_picturesize_ratio_key"."1.3333");
本文介绍了一个用于设置Android设备上摄像头默认像素的广播接收器。通过使用SharedPreferences,此接收器能够根据不同条件设定两种不同分辨率(1600x1200和2560x1920)作为摄像头的默认分辨率。
1062

被折叠的 条评论
为什么被折叠?



