In order to access Camera, we have to modify AndroidManifest.xml to grant permission of Camera.
package="com.exercise.AndroidCameraPictureSizes"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name">
Modify main.xml to have a Spinner to display the list.
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:id="@+id/supportedpicturesizes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Main Java code
package com.exercise.AndroidCameraPictureSizes;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class AndroidCameraPictureSizes extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinnerSupportedPictureSizes = (Spinner)findViewById(R.id.supportedpicturesizes);
Camera camera = Camera.open();
Camera.Parameters cameraParameters = camera.getParameters();
List listSupportedPictureSizes = cameraParameters.getSupportedPictureSizes();
List listStrSupportedPictureSizes = new ArrayList();
for (int i=0; i < listSupportedPictureSizes.size(); i++){
String strSize = String.valueOf(i) + " : "
+ String.valueOf(listSupportedPictureSizes.get(i).height)
+ " x "
+ String.valueOf(listSupportedPictureSizes.get(i).width);
listStrSupportedPictureSizes.add(strSize);
}
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, listStrSupportedPictureSizes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSupportedPictureSizes.setAdapter(adapter);
camera.release();
}
}
web support
www.klikcover.com
Tidak ada komentar:
Posting Komentar