安卓(Android) 怎么创建相机(Camera)首选项(Preferences)

2019年10月27日21:36:36安卓(Android) 怎么创建相机(Camera)首选项(Preferences)已关闭评论 337 1194字阅读3分58秒

1.简介

安卓(Android) 怎么创建相机(Camera)首选项(Preferences)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import java.util.StringTokenizer;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Camera;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class Main{
    private static SharedPreferences mSharedPreferences;
    private static void createCameraPreferences(Camera.Parameters params) {

        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putBoolean("initialized", true);

        StringTokenizer strParams = new StringTokenizer(params.flatten(),
                ";");
        while (strParams.hasMoreTokens()) {
            StringTokenizer entries = new StringTokenizer(
                    strParams.nextToken(), "=");
            String key, values;
            if (entries.countTokens() == 2) {
                key = entries.nextToken();
                values = entries.nextToken();
            } else {
                key = entries.nextToken();
                values = "";
            }

            for (int i = 0; i < CameraParameters.SUPPORT_PARAMS.length; i++) {
                if (key.compareTo(CameraParameters.SUPPORT_PARAMS[i]) == 0) {
                    editor.putString(key, values);
                }
            }
        }

        editor.commit();

        
        String thumbnailSize = mSharedPreferences.getString(
                "jpeg-thumbnail-width", "")
                + "x"
                + mSharedPreferences.getString("jpeg-thumbnail-height", "");
        editor.putString("thumbnail-size", thumbnailSize);
        editor.commit();
    }
}

 
继续阅读
编程十万个怎么办