私は教育目的で Android APP を作成しています。この APP は、サービスを呼び出し (タスクが終了するとサービスは終了します)、UI と音声なしで写真を撮ります。
このアプリは、私の古い HTC Desire (rooted) ではうまく機能しますが、Nexus4 では起動しません。私が間違っていることは何ですか?なぜ確かに携帯電話では機能するのに、他の携帯電話では機能しないのですか?
コード:
public class OIM_CameraControl extends Service
{
private final IBinder mBinder = new OIM_CameraControlBinder();
private Camera mCamera;
private Parameters parameters;
private TelephonyManager telephonyManager;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
SurfaceView sv = new SurfaceView(getApplicationContext());
if(mCamera == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Camera.CameraInfo info=new Camera.CameraInfo();
for (int i=0; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mCamera=Camera.open(i);
}
}
}
}
if (mCamera == null) {
System.out.println("No se ha detectado ninguna camara");
mCamera=Camera.open();
}
mCamera.setPreviewDisplay(sv.getHolder());
// I tried change parameters, add new parameters, delete parameters
// a lot of combinations,... never works in Nexus4.
parameters = mCamera.getParameters();
parameters.setPreviewSize(720, 480);
parameters.setPictureSize(720, 480);
parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
parameters.setZoom(0);
parameters.set("orientation", "portrait");
parameters.set("rotation",90);
mCamera.setParameters(parameters);
mCamera.startPreview();
mCamera.takePicture(null, null, mCall);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return START_NOT_STICKY;
}
private Camera.PictureCallback mCall = new Camera.PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
//Do something
}
};
//CLASES INTERNAS DE BINDER
public class OIM_CameraControlBinder extends Binder {
public OIM_CameraControl getService() {
return OIM_CameraControl.this;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
私のマニフェストでは:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
LogCat:
06-17 11:25:29.620: D/Camera(14346): app passed NULL surface
06-17 11:25:29.650: W/System.err(14346): java.lang.RuntimeException: takePicture failed
06-17 11:25:29.660: W/System.err(14346): at android.hardware.Camera.native_takePicture(Native Method)
06-17 11:25:29.660: W/System.err(14346): at android.hardware.Camera.takePicture(Camera.java:1095)
06-17 11:25:29.660: W/System.err(14346): at android.hardware.Camera.takePicture(Camera.java:1040)
06-17 11:25:29.660: W/System.err(14346): at com.obviousdevelop.estigia.objects.implement.OIM_CameraControl.onStartCommand(OIM_CameraControl.java:57)
06-17 11:25:29.660: W/System.err(14346): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2656)
06-17 11:25:29.660: W/System.err(14346): at android.app.ActivityThread.access$1900(ActivityThread.java:141)
06-17 11:25:29.660: W/System.err(14346): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
06-17 11:25:29.660: W/System.err(14346): at android.os.Handler.dispatchMessage(Handler.java:99)
06-17 11:25:29.660: W/System.err(14346): at android.os.Looper.loop(Looper.java:137)
06-17 11:25:29.660: W/System.err(14346): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-17 11:25:29.660: W/System.err(14346): at java.lang.reflect.Method.invokeNative(Native Method)
06-17 11:25:29.660: W/System.err(14346): at java.lang.reflect.Method.invoke(Method.java:511)
06-17 11:25:29.660: W/System.err(14346): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-17 11:25:29.660: W/System.err(14346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-17 11:25:29.660: W/System.err(14346): at dalvik.system.NativeStart.main(Native Method)
前もって感謝します!