2011-07-26 12 views
2

電話:私のコードではジンジャーブレッド2.3.3Androidエラー:Camera.open()でカメラサービスに接続できません。

とHTC信じられないほどの2、私がやっている:

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; 
    } 
} 

および

@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()の呼び出しはエンジンではなくアクティビティで行う必要があります。

これがなぜこのようなケースかわかりません。誰かが私にこの現象を説明できるかどうかは分かります。

+0

あなたは透明なライブ壁紙アプリケーションをチェックする必要があります。 –

0

cameraPreviewリリースカメラオブジェクトを停止した後。

あなたは何電話を使用しているこの

stopCameraPreview(){ 
    if(camera != null){ 
     camera.stopPreview(); 
     camera.release(); 
    } 
} 
関連する問題