shorty shorty - 1 year ago 69
Java Question

How do I get SharedPreference to work with Camera.Parameters setPreviewSize

How do i get SharedPreference to work for preview size of Android.Camera

My textbox contains the following string: "352, 288"

Previewsize = setingPreferences.getString("screensize", "");

I get the following compiler error:

setPreviewSize (int, int ) in parameters cannot be applied to int

I also tried with


but here I get this compiler error:

cannot resolve method getstring

Answer Source

I'll start out with explaining the two compiler errors you're receiving:

setPreviewSize (int, int ) in parameters cannot be applied to int

This tells you, that you're trying to parse a single int to the setPreviewSize method, while it actually takes two ints.

cannot resolve method getString

This simply means there's no method called getString.

If Previewsize is your string containing 352,288, you can perform a String split operation to split the two values into an array with two entries.

String previewSize = setingPreferences.getString("screensize", "");
String[] sizes = previewSize.split(",");
parameters.setPreviewSize(Integer.parseInt(sizes[0]), Integer.parseInt(sizes[1]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download