2009-11-16 57 views
4

我爲這篇較長的文章提前道歉,但有必要說明發生了什麼。無法連接到G1上的相機服務

我一直在研究一個適用於1.6模擬器的應用程序,但在我的G1上使用炸彈。

這裏是攝影師的活動:

public class Photographer extends Activity { 

private SurfaceView preview = null; 
private SurfaceHolder previewHolder = null; 
private Camera camera = null; 
public static final int IMAGE_HEIGHT = 320; 
public static final int IMAGE_WIDTH = 480; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.photographer); 

    preview = (SurfaceView)findViewById(R.id.preview); 
    previewHolder = preview.getHolder(); 
    previewHolder.addCallback(surfaceCallback); 
    previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
} 

private void takePicture() { 
    camera.stopPreview(); 
    camera.takePicture(null, null, photoCallback); 
} 

SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() { 
    public void surfaceCreated(SurfaceHolder holder) { 
    camera = Camera.open(); 

    try { 
    camera.setPreviewDisplay(previewHolder); 
    } 
    catch (Throwable t) { 
    Log.e("Photographer", "Exception in setPreviewDisplay()", t); 
    } 
    try { 
    takePicture(); 
    } catch (Throwable t) { 
    Log.e("Photographer", "Exception in takePicture()", t); 
    } 
    } 

    public void surfaceChanged(SurfaceHolder holder, 
     int format, int width, int height) { 
    Camera.Parameters parameters=camera.getParameters(); 
    parameters.setPreviewSize(IMAGE_WIDTH, IMAGE_HEIGHT); 
    parameters.setPictureFormat(PixelFormat.JPEG); 
    camera.setParameters(parameters); 
    camera.startPreview(); 
    } 

    public void surfaceDestroyed(SurfaceHolder holder) { 
    camera.stopPreview(); 
    camera.release(); 
    camera = null; 
    } 
}; 

Camera.PictureCallback photoCallback = new Camera.PictureCallback() { 
    public void onPictureTaken(byte[] data, Camera camera) { 
    new SavePhotoTask().execute(data); 
    camera.startPreview(); 
    } 
}; 

class SavePhotoTask extends AsyncTask<byte[], String, String> { 
    @Override 
    protected String doInBackground(byte[]... jpeg) { 
    File photo = new File(Environment.getExternalStorageDirectory(), "WIIA-new.jpg"); 
    if (photo.exists()) 
    photo.renameTo(new File(Environment.getExternalStorageDirectory(), "WIIA-old.jpg")); 

    try { 
    FileOutputStream fos = new FileOutputStream(photo.getPath()); 

    fos.write(jpeg[0]); 
    fos.close(); 
    Log.e("Photographer", "Picture taken"); 
    // returning result 
     Intent returnIntent = new Intent(); 
     setResult(RESULT_OK, returnIntent);  
     finish(); 
    } 
    catch (java.io.IOException e) { 
    Log.e("Photographer", "Exception in photoCallback", e); 

    // returning result 
     Intent returnIntent = new Intent(); 
    setResult(RESULT_CANCELED, returnIntent); 
    finish(); 
    } 

    return(null); 
    } 
} 

} 

和這裏是本次活動得到來自名爲:

public class WIIA extends Activity { 

public class CountDown extends CountDownTimer { 
    private TextView tvCountDown = (TextView) findViewById(R.id.progress); 
    private TextView tvSystemState = (TextView) findViewById(R.id.system_state); 

    public CountDown(long millisInFuture, long countDownInterval) { 
    super(millisInFuture, countDownInterval); 
    } 

    @Override 
    public void onFinish() { 
    tvSystemState.setText(R.string.system_state_armed); 
    tvCountDown.setText(R.string.armed); 
    snapshotInterval = Long.parseLong(settings.getString("snapshot_interval_list", "5")); 
    imgCaptureTimer = new Timer("imageCapture"); 
    imgCaptureTimer.scheduleAtFixedRate(doRefresh, 0, snapshotInterval*1000); 
    } 

    @Override 
    public void onTick(long millisUntilFinished) { 
    tvCountDown.setText(millisUntilFinished/1000 + " seconds until Armed"); 
    } 

} 

private TimerTask doRefresh = new TimerTask() { 
    public void run() { 
    if (armed) { 
    refreshImage(); 
    } else { 
    imgCaptureTimer.cancel(); 
    } 
    } 
}; 

private void refreshImage() { 
    Thread updateThread = new Thread(null, backgroundCaptureImage, "capture_image"); 
    updateThread.start();   
} 

private Runnable backgroundCaptureImage = new Runnable() { 
    public void run() { 
    doRefreshImage(); 
    }   
}; 

private void doRefreshImage() { 
    Intent photographer = new Intent(this, Photographer.class); 
    startActivityForResult(photographer, GET_PHOTO); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) { 
    case (GET_PHOTO) : { 
    if(resultCode == RESULT_OK) { 
    // go on to compare images 
    new ProcessImageTask().execute(); 
    } 
    break; 
    } 
    } 
} 

順利粘貼AndroidManifest.xml中的相關部分,但是我有權限照相機:

<uses-permission android:name="android.permission.CAMERA" /> 

這裏是攝影師部分:

 <activity android:name=".Photographer" 
    android:configChanges="keyboardHidden|orientation" 
    android:screenOrientation="landscape" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
    </activity> 

還爲測試在G1:

android:debuggable="true" 

和關閉的1.6工作:

<uses-sdk android:minSdkVersion="4" /> 

所有這些工作在一個1.6模擬器,但是當我在G1上運行此,LogCat顯示:

INFO/ActivityManager(74): Starting activity: Intent { cmp=com.androidsecurity.wiia/.Photographer } 

WARN/WindowManager(74): App freeze timeout expired. 

WARN/WindowManager(74): Force clearing freeze: AppWindowToken{432e1520 token=HistoryRecord{43124c10 com.androidsecurity.wiia/.Photographer}} 

WARN/ActivityManager(74): Activity pause timeout for HistoryRecord{43124c10 com.androidsecurity.wiia/.Photographer} 

ERROR/QualcommCameraHardware(51): native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd 13 error Connection timed out 

ERROR/QualcommCameraHardware(51): getPicture failed! 

DEBUG/QualcommCameraHardware(51): snapshot_thread X 

INFO/QualcommCameraHardware(51): initPreview E: preview size=480x320 

DEBUG/QualcommCameraHardware(51): frame_thread E 

DEBUG/CameraService(51): CameraService::connect E (pid 1031, client 0x3b510) 

DEBUG/CameraService(51): CameraService::connect X (pid 1031, new client 0x3b510) rejected. (old pid 1031, old client 0x3b2e0) 

DEBUG/AndroidRuntime(1031): Shutting down VM 

WARN/dalvikvm(1031): threadid=3: thread exiting with uncaught exception (group=0x4001da28) 

ERROR/AndroidRuntime(1031): Uncaught handler: thread main exiting due to uncaught exception 

ERROR/AndroidRuntime(1031): java.lang.RuntimeException: Fail to connect to camera service 

ERROR/AndroidRuntime(1031):  at android.hardware.Camera.native_setup(Native Method) 

ERROR/AndroidRuntime(1031):  at android.hardware.Camera.native_setup(Native Method) 

ERROR/AndroidRuntime(1031):  at android.hardware.Camera.open(Camera.java:67) 

ERROR/AndroidRuntime(1031):  at com.androidsecurity.wiia.Photographer$1.surfaceCreated(Photographer.java:78) 

ERROR/AndroidRuntime(1031):  at android.view.SurfaceView.updateWindow(SurfaceView.java:392) 

ERROR/AndroidRuntime(1031):  at android.view.SurfaceView.dispatchDraw(SurfaceView.java:264) 

ERROR/AndroidRuntime(1031):  at android.view.ViewGroup.drawChild(ViewGroup.java:1524) 

ERROR/AndroidRuntime(1031):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256) 

ERROR/AndroidRuntime(1031):  at android.view.ViewGroup.drawChild(ViewGroup.java:1524) 

ERROR/AndroidRuntime(1031):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256) 

ERROR/AndroidRuntime(1031):  at android.view.View.draw(View.java:6277) 

ERROR/AndroidRuntime(1031):  at android.widget.FrameLayout.draw(FrameLayout.java:352) 

ERROR/AndroidRuntime(1031):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1883) 

ERROR/AndroidRuntime(1031):  at android.view.ViewRoot.draw(ViewRoot.java:1332) 

ERROR/AndroidRuntime(1031):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1097) 

ERROR/AndroidRuntime(1031):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 

ERROR/AndroidRuntime(1031):  at android.os.Handler.dispatchMessage(Handler.java:99) 

ERROR/AndroidRuntime(1031):  at android.os.Looper.loop(Looper.java:123) 

ERROR/AndroidRuntime(1031):  at android.app.ActivityThread.main(ActivityThread.java:4203) 

ERROR/AndroidRuntime(1031):  at java.lang.reflect.Method.invokeNative(Native Method) 

ERROR/AndroidRuntime(1031):  at java.lang.reflect.Method.invoke(Method.java:521) 

ERROR/AndroidRuntime(1031):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 

ERROR/AndroidRuntime(1031):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 

ERROR/AndroidRuntime(1031):  at dalvik.system.NativeStart.main(Native Method) 

和/data/anr/traces.txt顯示:

`DALVIK THREADS: 
"main" prio=5 tid=3 NATIVE 
    | group="main" sCount=1 dsCount=0 s=N obj=0x4001db08 self=0xbc48 
    | sysTid=358 nice=0 sched=0/0 handle=-1343996920 
    at android.os.BinderProxy.transact(Native Method) 
    at android.app.ActivityManagerProxy.handleApplicationError(ActivityManagerNative.java:2243) 
    at com.android.internal.os.RuntimeInit.crash(RuntimeInit.java:302) 
    at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:75) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:887) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:884) 
    at dalvik.system.NativeStart.main(Native Method) 

"imageCapture" prio=5 tid=17 TIMED_WAIT 
    | group="main" sCount=1 dsCount=0 s=N obj=0x432a66f0 self=0x1dc820 
    | sysTid=366 nice=0 sched=0/0 handle=1938080 
    at java.lang.Object.wait(Native Method) 
    - waiting on <0x1c8cd8> (a java.util.Timer$TimerImpl) 
    at java.lang.Object.wait(Object.java:326) 
    at java.util.Timer$TimerImpl.run(Timer.java:250) 

"Binder Thread #3" prio=5 tid=15 NATIVE 
    | group="main" sCount=1 dsCount=0 s=N obj=0x4327aa38 self=0x160ea0 
    | sysTid=365 nice=0 sched=0/0 handle=1406616 
    at dalvik.system.NativeStart.run(Native Method) 

"Binder Thread #2" prio=5 tid=13 NATIVE 
    | group="main" sCount=1 dsCount=0 s=N obj=0x4327a978 self=0x1609c0 
    | sysTid=364 nice=0 sched=0/0 handle=498392 
    at dalvik.system.NativeStart.run(Native Method) 

"Binder Thread #1" prio=5 tid=11 NATIVE 
    | group="main" sCount=1 dsCount=0 s=N obj=0x432799d0 self=0x155268 
    | sysTid=363 nice=0 sched=0/0 handle=1397288 
    at dalvik.system.NativeStart.run(Native Method) 

"JDWP" daemon prio=5 tid=9 VMWAIT 
    | group="system" sCount=1 dsCount=0 s=N obj=0x432782a0 self=0x15f788 
    | sysTid=361 nice=0 sched=0/0 handle=1614352 
    at dalvik.system.NativeStart.run(Native Method) 

"Signal Catcher" daemon prio=5 tid=7 RUNNABLE 
    | group="system" sCount=0 dsCount=0 s=N obj=0x432781e8 self=0x18a0f0 
    | sysTid=360 nice=0 sched=0/0 handle=1614000 
    at dalvik.system.NativeStart.run(Native Method) 

"HeapWorker" daemon prio=5 tid=5 VMWAIT 
    | group="system" sCount=1 dsCount=0 s=N obj=0x422dd3e8 self=0x1177a8 
    | sysTid=359 nice=0 sched=0/0 handle=1613728 
    at dalvik.system.NativeStart.run(Native Method)` 

這聽起來像問題是超時問題,但我不知所措的地方,我應該尋找....沒有任何人有線索?

謝謝!

+0

我認爲這是夢幻般的,我現在還在2015年 – 2015-03-05 22:42:39

回答

6

嘗試定義應用程序標記外的許可標記,像下面,我希望這有助於:

<manifest ......> <uses-permission android:name="android.permission.CAMERA" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity ... .....> </application> </manifest>

+0

達不到這個問題謝謝@ravi這對我很有用... :) – NagarjunaReddy 2012-03-24 03:52:58

+0

救了我一個真正的痛苦THX很多 – TheFuquan 2014-10-10 11:50:31

14

最有可能的cameraService這是媒體過程的一部分在後臺崩潰。如果您只是嘗試在Android中運行默認相機應用程序,並且不顯示,那麼只需重新引導設備即可解決此問題。

+4

有無論如何,要解決這個問題的代碼,我捕捉異常,但不能準確告訴用戶重新啓動他們的設備。 – sgarman 2011-09-14 18:22:09

+0

這也適用於我,但斯曼說我不能告訴用戶重新啓動他的手機。 – 2013-09-17 14:31:19

相關問題