2011-07-26 60 views
2

電話:HTC不可思議2薑餅2.3.3Android錯誤:無法連接到Camera.open()上的攝像頭服務?

在我的代碼,我做的:

cam = Camera.open(0); 
SurfaceHolder surfaceHolder = getSurfaceHolder(); 
try 
{ 
    cam.setPreviewDisplay(surfaceHolder); 
    cam.startPreview(); 
} 
catch (IOException e) 
{ 
    e.printStackTrace(); 
} 

在一個發動機

構造我也有:

@Override 
public void onDestroy() 
{ 
    super.onDestroy(); 
    if (cam != null) 
    { 
     cam.stopPreview(); 
     cam.setPreviewCallback(null); 
     cam.release(); 
     cam = null; 
    } 
} 

and

@Override 
public void onSurfaceDestroyed(SurfaceHolder holder) 
{ 
    super.onSurfaceDestroyed(holder); 
    if (cam != null) 
    { 
     cam.stopPreview(); 
     cam.setPreviewCallback(null); 
     cam.release(); 
     cam = null; 
    } 
} 

我的清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.android.google.apis" android:versionCode="1" 
    android:versionName="1.0"> 

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

    <uses-feature android:name="android.software.live_wallpaper" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <service android:label="@string/label" 
      android:name="com.me.app.main.AppName" 
      android:permission="android.permission.BIND_WALLPAPER"> 
      <intent-filter> 
       <action android:name="android.service.wallpaper.WallpaperService" /> 
      </intent-filter> 
      <meta-data android:name="android.service.wallpaper" 
       android:resource="@xml/app" /> 
     </service> 
     <activity 
      android:name="com.me.app.main.AppName" 
      android:label="@string/app_name"> 
      android:exported="true"> 
     </activity> 

    </application> 
</manifest> 
+0

您正在使用什麼手機? – gsfd

+0

薑餅令人難以置信的2 2.3.3 –

回答

2

我想通了。原來,Camera.open()調用必須在Activity中進行,而不是在Engine中進行。

不知道爲什麼會出現這種情況。如果有人能向我解釋這種現象,我將不勝感激。

+0

你應該檢查透明的動態壁紙應用程序。 –

0

停止cameraPreview釋放相機對象後。

試試這個

stopCameraPreview(){ 
    if(camera != null){ 
     camera.stopPreview(); 
     camera.release(); 
    } 
} 
相關問題