IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Android Discussion :

Ouverture de la caméra


Sujet :

API standards et tierces Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 60
    Par défaut Ouverture de la caméra
    Bonjour à tous, j'ai un petit problème lorsque j'essaye d'utiliser la caméra : ça marche avec un émulateur API8, mais pas sur un avec la version 2.3.1 d'android.
    J'ai aussi testé sur un téléphone (HTC Desire) et ça plante : dans le log cat j'ai "Fail to connect to camera service" sur la ligne "Camera.open();"

    J'ai mis la permission dans le manifest, et déjà regardé sur le net, je n'ai rien trouvé, si quelqu'un à une solution, voilà le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
     
    public class Preview extends SurfaceView implements SurfaceHolder.Callback{
            SurfaceHolder mHolder;
            Camera mCamera;
     
            public Preview(Context context, AttributeSet att) {
                    super(context, att);
     
                    // Install a SurfaceHolder.Callback so we get notified when the
                    // underlying surface is created and destroyed.
                    mHolder = getHolder();
                    mHolder.addCallback(this);
                    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            }
     
            public Preview(Context context) {
                    super(context);
     
                    // Install a SurfaceHolder.Callback so we get notified when the
                    // underlying surface is created and destroyed.
                    mHolder = getHolder();
                    mHolder.addCallback(this);
                    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            }
     
            public Camera getCamera(){
                    return mCamera;
            }
     
            public void surfaceCreated(SurfaceHolder holder) {
                    // The Surface has been created, acquire the camera and tell it where
                    // to draw.
                    mCamera = Camera.open();
                    try {
                       mCamera.setPreviewDisplay(holder);
                    } catch (IOException exception) {
                            mCamera.release();
                            mCamera = null;
                            // TODO: add more exception handling logic here
                    }
            }
     
            public void surfaceDestroyed(SurfaceHolder holder) {
                    // Surface will be destroyed when we return, so stop the preview.
                    // Because the CameraDevice object is not a shared resource, it's very
                    // important to release it when the activity is paused.
                    mCamera.stopPreview();
                    mCamera.release();
                    mCamera = null;
            }
     
            public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
                    // Now that the size is known, set up the camera parameters and begin
                    // the preview.
                    Camera.Parameters parameters = mCamera.getParameters();
                    parameters.setPreviewSize(h, w);
                    mCamera.setParameters(parameters);
                    mCamera.startPreview();
            }
     
    }

  2. #2
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Bonjour,

    Pourrais tu nous poster l'erreur complète dans ton logcat , ainsi que ton fichier manifest ?

    Merci,

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 60
    Par défaut
    Le manifest :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.chloro"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="4" />
        <uses-permission android:name="android.permission.CAMERA"></uses-permission>
        <uses-permission android:name="android.permission.INTERNET"></uses-permission>
     
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light">
     
            <activity android:name=".Main"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
     
            <activity android:name=".Controleurs.Liste_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
           	<activity android:name=".Controleurs.Grille_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
           	<activity android:name=".Controleurs.Item_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
            <activity android:name=".Controleurs.Camera_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
           	<activity android:name=".Controleurs.Web_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    Le logcat complet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    03-01 15:43:19.162: ERROR/AndroidRuntime(402): FATAL EXCEPTION: main
    03-01 15:43:19.162: ERROR/AndroidRuntime(402): java.lang.RuntimeException: Fail to connect to camera service
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.hardware.Camera.native_setup(Native Method)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.hardware.Camera.<init>(Camera.java:258)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.hardware.Camera.open(Camera.java:235)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at com.android.chloro.Vues.Preview.surfaceCreated(Preview.java:42)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.View.draw(View.java:6883)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.View.draw(View.java:6883)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewRoot.draw(ViewRoot.java:1522)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.os.Handler.dispatchMessage(Handler.java:99)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.os.Looper.loop(Looper.java:123)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at android.app.ActivityThread.main(ActivityThread.java:3647)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at java.lang.reflect.Method.invokeNative(Native Method)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at java.lang.reflect.Method.invoke(Method.java:507)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    03-01 15:43:19.162: ERROR/AndroidRuntime(402):     at dalvik.system.NativeStart.main(Native Method)

  4. #4
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Essaye avec ça

    android:screenOrientation="landscape" dans le manifest

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.chloro"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="4" />
        <uses-permission android:name="android.permission.CAMERA"></uses-permission>
        <uses-permission android:name="android.permission.INTERNET"></uses-permission>
     
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light">
     
            <activity android:name=".Main"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
     
            <activity android:name=".Controleurs.Liste_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
           	<activity android:name=".Controleurs.Grille_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
           	<activity android:name=".Controleurs.Item_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
            <activity android:name=".Controleurs.Camera_c"
                      android:label="@string/app_name"
                      android:screenOrientation="landscape">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
           	<activity android:name=".Controleurs.Web_c"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    Je crois qu'il faut avoir l'écran en mode paysage pour la caméra .

    Si tu veux passer en portrait il suffit de faire une rotation sur la caméra .

    Si tu ne veux pas passer par le manifest il te suffit de placer ce morceau de code dans le onCreate
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 60
    Par défaut
    J'avais déjà essayé, toujours la même erreur.

  6. #6
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Je sais qu'il y a une nouvelle révision sur la Caméra a partir de l'API 9.

    public static Camera open (int cameraId)
    Since: API Level 9

    Creates a new Camera object to access a particular hardware camera.

    You must call release() when you are done using the camera, otherwise it will remain locked and be unavailable to other applications.

    Your application should only have one Camera object active at a time for a particular hardware camera.

    Callbacks from other methods are delivered to the event loop of the thread which called open(). If this thread has no event loop, then callbacks are delivered to the main application event loop. If there is no main application event loop, callbacks are not delivered.

    Caution: On some devices, this method may take a long time to complete. It is best to call this method from a worker thread (possibly using AsyncTask) to avoid blocking the main application UI thread.
    Parameters
    cameraId the hardware camera to access, between 0 and getNumberOfCameras()-1.
    Returns

    * a new Camera object, connected, locked and ready for use.

    Throws
    RuntimeException if connection to the camera service fails (for example, if the camera is in use by another process).
    Tu n'as pas d'autre caméra qui tourne ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. piloter caméra à distance et ouverture de popup
    Par justin92330 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 23/09/2008, 12h02
  2. Resau local => ouverture et fermeture
    Par Nutcase dans le forum Développement
    Réponses: 8
    Dernier message: 17/11/2002, 15h16
  3. [TForm] Ne pas autoriser l'ouverture d'un form
    Par sbeu dans le forum Composants VCL
    Réponses: 6
    Dernier message: 11/10/2002, 11h20
  4. Réponses: 2
    Dernier message: 22/07/2002, 12h13
  5. Réponses: 2
    Dernier message: 04/06/2002, 10h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo