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

Android Discussion :

Android plantage d'application


Sujet :

Android

  1. #1
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut Android plantage d'application
    Bonjour

    mon application utilise le bluetooth, en cas de probleme de l'adresse l'application se plante toute entiere, pour eviter ça, je cherche comme le C# un truc comme le try catch pour au moment l'application crash il ne se plante pas mais juste elle fait rien, comme ça quand l'utilisateur entre la bonne adresse l'application fonctionne

    je fais ce genre de try catch
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
                try {
                    outStream = btSocket.getOutputStream();
                } catch (IOException e) {
                    errorExit("Fatal Error", "In onResume() and output stream creation failed:" + e.getMessage() + ".");
                }
    mais il n'est pas comme le C# car l'application plante apres le message s'affiche :/

    voila j'ai besoin d'aide

  2. #2
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    Avec ton bout de code et l'absence de l'erreur, il est impossible de t'aiguiller.
    Le système de try/catch de Java fonctionne. Le problème ne se situe pas à ce niveau.
    Fournis-nous le log d'erreur (la stracktrace complète), ce qu'il se passe, le code de ta méthode (ainsi que celui des méthodes personnelles appelées) et le souci que tu as (autre que "ça crash") et nous pourrons t'aider
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  3. #3
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut
    Merci pour votre réponse, voici tout les erreurs que j'obtiens(l'intent principale et l'intente secondaire):

    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    09-16 13:13:19.170  11594-15800/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:19.180    7152-7179/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:19.368  11594-15812/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:19.370    7152-8090/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:19.537   9249-15095/? E/bt-btif﹕ bta_jv_port_mgmt_cl_cback, p_cb:0x0, p_cb->p_cback:0x0, p_pcb
    09-16 13:13:19.840  24848-24865/? E/QCOM PowerHAL﹕ Failed to acquire lock.
    09-16 13:13:19.840  24848-24865/? E/QCOM PowerHAL﹕ Failed to acquire lock.
    09-16 13:13:19.909  24848-25630/? E/QCOM PowerHAL﹕ Failed to acquire lock.
    09-16 13:13:23.356   9249-15095/? E/bt-btm﹕ btm_sec_disconnected - Clearing Pending flag
    09-16 13:13:26.577   9249-15095/? E/bt-btif﹕ DISCOVERY_COMP_EVT slot id:6, failed to find channle,                                       status:1, scn:0
    09-16 13:13:27.749  24848-25630/? E/QCOM PowerHAL﹕ Failed to acquire lock.
    09-16 13:13:27.840  24848-25518/? E/QCOM PowerHAL﹕ Failed to acquire lock.
    09-16 13:13:28.686  11594-15922/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:28.689    7152-7179/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:28.980  11594-15933/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:28.983    7152-7178/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:30.804   9249-15095/? E/bt-btif﹕ bte_scan_filt_param_cfg_evt, 1
    09-16 13:13:30.805   9249-15095/? E/bt-btif﹕ bte_scan_filt_param_cfg_evt, 1
    09-16 13:13:35.428  11594-15971/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:35.434    7152-7171/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:35.570  11594-15981/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:35.574    7152-7180/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:38.896   9249-15095/? E/bt-btif﹕ DISCOVERY_COMP_EVT slot id:6, failed to find channle,                                       status:1, scn:0
    09-16 13:13:41.838  11594-16054/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:41.842    7152-7171/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    09-16 13:13:42.054  11594-16061/? E/ActivityThread﹕ Failed to find provider info for com.facebook.wakizashi.provider.MessagesForegroundProvider
    09-16 13:13:42.061    7152-7172/? E/DatabaseUtils﹕ Writing exception to parcel
        java.lang.SecurityException: Signature mismatch
                at com.facebook.orca.notify.MessengerForegroundProvider.a(MessengerForegroundProvider.java:132)
                at com.facebook.content.a.b(AbstractContentProvider.java:146)
                at com.facebook.content.a.query(AbstractContentProvider.java:411)
                at android.content.ContentProvider$Transport.query(ContentProvider.java:214)
                at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                at android.os.Binder.execTransact(Binder.java:446)
    bizarement, mon application fonctionne parfois et parfois il se plante et donc je ne sais plus ou est le probleme, si tu veux le code je le partage mais c'est long(code bluetooth pour envoyé un numéro)

  4. #4
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut
    Bon l'erreur seul ne suffit pas, je te partage le code ici et à toi de voir.

    bon mon code est simple il a deux interfaces, face UN qui permet d'envoyé un numéro comme 1 ou 2 ou 3 ou 4 ou 5...

    et l'interface deux qui cherche les telephones bluetooth.

    donc voici le code de l'interface N° 1:

    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    package com.adrian.test.test1;
     
    import android.app.Activity;
    import android.bluetooth.BluetoothAdapter;
    import android.bluetooth.BluetoothDevice;
    import android.bluetooth.BluetoothSocket;
    import android.content.Intent;
    import android.os.Build;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
     
    import java.io.IOException;
    import java.io.OutputStream;
    import java.lang.reflect.Method;
    import java.util.UUID;
     
    public class MainActivity extends Activity implements OnClickListener {
        private static final String TAG = "bluetooth1";
     
        boolean active = true;
        Button btnOn, btnOff, connect;
        Intent intent;
     
        private BluetoothAdapter btAdapter = null;
        private BluetoothSocket btSocket = null;
        private OutputStream outStream = null;
     
        // SPP UUID service
        private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
     
        // MAC-address of Bluetooth module (you must edit this line)
        private static String address = "00:00:00:00:00:00";//"98:D3:31:40:59:B6";
        String myaddress = "";
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            setContentView(R.layout.activity_main);
     
            btnOn = (Button) findViewById(R.id.buttonon);
            btnOff = (Button) findViewById(R.id.buttonoff);
            connect = (Button)findViewById(R.id.button2);
     
            connect.setOnClickListener(this);
     
            //checkBTState();
     
            btnOn.setOnClickListener(this);
            btnOff.setOnClickListener(this);
     
     
            /*btnOff.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
     
     
                }
            });*/
     
            intent = new Intent(this, Search.class);
     
        }
     
        private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
            if(Build.VERSION.SDK_INT >= 10){
                try {
                    final Method  m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
                    return (BluetoothSocket) m.invoke(device, MY_UUID);
                } catch (Exception e) {
                    Log.e(TAG, "Could not create Insecure RFComm Connection",e);
                }
            }
            return  device.createRfcommSocketToServiceRecord(MY_UUID);
        }
     
        @Override
        public void onResume() {
            super.onResume();
     
            Log.d(TAG, "...onResume - try connect...");
     
            btAdapter = BluetoothAdapter.getDefaultAdapter();
            // Set up a pointer to the remote node using it's address.
            BluetoothDevice device = btAdapter.getRemoteDevice(address);
     
            // Two things are needed to make a connection:
            //   A MAC address, which we got above.
            //   A Service ID or UUID.  In this case we are using the
            //     UUID for SPP.
     
            try {
                btSocket = createBluetoothSocket(device);
            } catch (IOException e1) {
                errorExit("Fatal Error", "In onResume() and socket create failed: " + e1.getMessage() + ".");
            }
     
        /*try {
          btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) {
          errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
        }*/
     
            // Discovery is resource intensive.  Make sure it isn't going on
            // when you attempt to connect and pass your message.
            btAdapter.cancelDiscovery();
     
            // Establish the connection.  This will block until it connects.
            Log.d(TAG, "...Connecting...");
            try {
                btSocket.connect();
                Log.d(TAG, "...Connection ok...");
            } catch (IOException e) {
                try {
                    btSocket.close();
                } catch (IOException e2) {
                    errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
                }
            }
     
            // Create a data stream so we can talk to server.
            Log.d(TAG, "...Create Socket...");
     
            try {
                outStream = btSocket.getOutputStream();
            } catch (IOException e) {
                errorExit("Fatal Error", "In onResume() and output stream creation failed:" + e.getMessage() + ".");
            }
        }
     
        @Override
        public void onPause() {
            super.onPause();
     
            Log.d(TAG, "...In onPause()...");
     
            if (outStream != null) {
                try {
                    outStream.flush();
                } catch (IOException e) {
                    //errorExit("Fatal Error", "In onPause() and failed to flush output stream: " + e.getMessage() + ".");
                }
            }
     
            try     {
                btSocket.close();
            } catch (IOException e2) {
                //errorExit("Fatal Error", "In onPause() and failed to close socket." + e2.getMessage() + ".");
            }
        }
     
        //private void checkBTState() {
            // Check for Bluetooth support and then check to make sure it is turned on
            // Emulator doesn't support Bluetooth and will return null
         /*   if(btAdapter==null) {
                errorExit("Fatal Error", "Bluetooth not support");
            } else {
                if (btAdapter.isEnabled()) {
                    Log.d(TAG, "...Bluetooth ON...");
                } else {
                    //Prompt user to turn on Bluetooth
                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, 1);
                }
            }
        }*/
     
        private void errorExit(String title, String message){
            Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show();
            finish();
        }
     
        private void sendData(String message) {
     
            byte[] msgBuffer = message.getBytes();
     
            Log.d(TAG, "...Send data: " + message + "...");
     
            try {
                outStream.write(msgBuffer);
            } catch (IOException e) {
                String msg = "In onResume() and an exception occurred during write: " + e.getMessage();
                if (address.equals("00:00:00:00:00:00"))
                    msg = msg + ".\n\nUpdate your server address from 00:00:00:00:00:00 to the correct address on line 35 in the java code";
                msg = msg +  ".\n\nCheck that the SPP UUID: " + MY_UUID.toString() + " exists on server.\n\n";
     
                errorExit("Fatal Error", msg);
            }
        }
     
        @Override
        public void onClick(View v) {
     
            if(active == false)
            {
                address = myaddress;
                btAdapter = BluetoothAdapter.getDefaultAdapter();
                BluetoothDevice device = btAdapter.getRemoteDevice(address);
                try {
                    btSocket = createBluetoothSocket(device);
                } catch (IOException e1) {
                    errorExit("Fatal Error", "In onResume() and socket create failed: " + e1.getMessage() + ".");
                }
                //btAdapter.cancelDiscovery();
     
                // Establish the connection.  This will block until it connects.
                Log.d(TAG, "...Connecting...");
                try {
                    btSocket.connect();
                    Log.d(TAG, "...Connection ok...");
                } catch (IOException e) {
                    try {
                        btSocket.close();
                    } catch (IOException e2) {
                        errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
                    }
                }
                // Create a data stream so we can talk to server.
                Log.d(TAG, "...Create Socket...");
     
                try {
                    outStream = btSocket.getOutputStream();
                } catch (IOException e) {
                    errorExit("Fatal Error", "In onResume() and output stream creation failed:" + e.getMessage() + ".");
                }
                active = true;
            }
            if(v.getId() == R.id.button2)
            {
                this.startActivityForResult(intent, 1000);
            }
            if(v.getId() == R.id.buttonoff)
            {
                sendData("0");
                Toast.makeText(getBaseContext(), "OFF", Toast.LENGTH_SHORT).show();
            }
            if(v.getId() == R.id.buttonon)
            {
                sendData("1");
                Toast.makeText(getBaseContext(), "ON", Toast.LENGTH_SHORT).show();
            }
        }
     
        //onActivityResult c'est juste pour recuperer les données de la sous activité
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(requestCode == 1000)
            {
                myaddress = data.getStringExtra("RESULT_STRING");
                btnOn.setEnabled(true);
                btnOff.setEnabled(true);
                active = false;
            }
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    et voici le code de l'interface N° 2:

    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    package com.adrian.test.test1;
     
    import android.app.Activity;
    import android.bluetooth.BluetoothAdapter;
    import android.bluetooth.BluetoothDevice;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
     
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Set;
     
    public class Search extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {
     
        ListView listview;
        //ArrayAdapter btarrayadapter;
        ArrayList<HashMap<String, String>> listItem;
        //On déclare la HashMap qui contiendra les informations pour un item
        HashMap<String, String> map;
        SimpleAdapter mSchedule;
     
        BroadcastReceiver broadcastReceiver;
        Button searchbtn;
        BluetoothAdapter bluetoothAdapter;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            setContentView(R.layout.connecting_interface);
     
            listview = (ListView)findViewById(R.id.listView);
            listview.setOnItemClickListener(this);
     
            searchbtn = (Button)findViewById(R.id.button3);
            searchbtn.setOnClickListener(this);
     
            //btarrayadapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
     
            listItem = new ArrayList<HashMap<String, String>>();
     
            bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
     
            //verification si le telephone support le bluetooth
     
            if(bluetoothAdapter == null)
            {
                Toast.makeText(this, "Bluetooth not supported in your device.", Toast.LENGTH_LONG).show();
                finish();
            }
     
            //verification si le bluetooth est activé
     
            if(!bluetoothAdapter.isEnabled())
            {
                Intent BluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivity(BluetoothIntent);
            }
     
            //chercher les appareils qui sont des apparés dans le smartphone, donc des appareils qui sont deja connu
     
            Set<BluetoothDevice> paireddevices = bluetoothAdapter.getBondedDevices();//cette ligne renvoi un tableau des devices qui sont deja apparé
     
            //verifier si le tableau contient qui infos
            if(paireddevices.size() > 0)
            {
     
                for(BluetoothDevice bluetoothDevice : paireddevices)
                {
                    //ajouter les infos dans l'adapter pour la listeview
                    //btarrayadapter.add(bluetoothAdapter.getName());
     
                    //Création d'une HashMap pour insérer les informations du premier item de notre listView
                    map = new HashMap<String, String>();
                    map.put("titre", bluetoothDevice.getName() + " - Appairé");
                    map.put("description", bluetoothDevice.getAddress());
                    //listItem.add(map);
                    addIfNotContains(map);
                }
            }
     
            //chercher des nouveaux devices
     
            broadcastReceiver = new BroadcastReceiver() {
     
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (BluetoothDevice.ACTION_FOUND.equals(action)) {//s'il detecte un nouveau device
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        //ajouter les infos dans l'adapter pour la listeview
                        //btarrayadapter.add(device.getName());
     
                        //Création d'une HashMap pour insérer les informations du premier item de notre listView
                        map = new HashMap<String, String>();
                        map.put("titre", device.getName());
                        map.put("description", device.getAddress());
                        //listItem.add(map);
                        addIfNotContains(map);
                    }
                }
            };
     
            IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(broadcastReceiver, filter);
     
            //devenir visible
            Intent discoverableintent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableintent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
            startActivity(discoverableintent);
     
        }
     
        //fonction qui compare les adresses mac et c'est pour eviter les doublement dans la listeview
        private void addIfNotContains(HashMap<String, String> map){
            boolean contains = false;
            for(HashMap<String, String> m : listItem){
                if(m.get("description").equals(map.get("description"))) contains = true;
            }
            if(!contains) listItem.add(map);
        }
     
     
     
        @Override
        protected void onDestroy() {
            unregisterReceiver(broadcastReceiver);
            super.onDestroy();
        }
     
        @Override
        public void onClick(View v) {
     
            Toast.makeText(getBaseContext(), "Press that button again if you didn't see your device.", Toast.LENGTH_SHORT).show();
     
            bluetoothAdapter.startDiscovery();
     
            //listview.setAdapter(btarrayadapter);
     
            //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
     
            mSchedule = new SimpleAdapter(this, listItem, R.layout.affichageitem, new String[] {"titre", "description"}, new int[] {R.id.titre, R.id.description});
     
            listview.setAdapter(mSchedule);
     
        }
     
        //fonction pour desactiver la touche retour de téléphone
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
     
        //fonction pour envoyé une valeur à la premiere fenetre de l'application
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            map = (HashMap<String, String>) listview.getItemAtPosition(position);
     
            Intent intent=new Intent();
            intent.putExtra("RESULT_STRING", map.get("description"));
     
            setResult(1000, intent);
            //this.startActivityForResult(intent, 1000);
            finish();
        }
    }

  5. #5
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    Les erreurs mises proviennent de Facebook, de l'application Facebook semblerait-il.
    Es-tu sûr que celles-ci correspondent à ton problème ? Il n'y a aucune mention de tes classes.

    Si je me fie à l'extrait de code que tu as fourni en premier et que je lis sa place dans le code général, l'application plante durant l'envoi des messages.
    N'ayant jamais joué avec le Bluetooth, je n'ai pas mémoire d'un cas similaire.
    Je te suggère, par contre, de changer ton "errorExit" pour qu'il prenne l'Exception en argument et de la fournir au Log.e (Log.e("TAG", "message", e);), cela te permettra, dans le futur, d'avoir des informations plus parlantes que le message associé à l'Exception (qui peut être null).
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  6. #6
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut
    J'ai suis tes conseils donc j'ai fait log.e et il m'a donné ça:

    09-16 21:19:55.091 30886-30886/? E/Fatal Error﹕ In onResume() and socket create failed: In onResume() and an exception occurred during write: socket closed.
    Check that the SPP UUID: 00001101-0000-1000-8000-00805f9b34fb exists on server.

    comme j'ai mentionné en haut par fois l'application marche sans probleme, parfois cette erreur sort



    bon apres plusieurs teste, j'ai vu que la carte bluetooth se plante je ne sais pas peut etre parce que je teste beaucoup l'essentiel c'est quand il se plante je recoi directement ce message
    09-16 21:19:55.091 30886-30886/? E/Fatal Error﹕ In onResume() and socket create failed: In onResume() and an exception occurred during write: socket closed.
    Check that the SPP UUID: 00001101-0000-1000-8000-00805f9b34fb exists on server.

  7. #7
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    Tu n'as pas le type de l'Exception dans tes logs ? Si oui, tu peux la catcher et réaliser un traitement pour éviter le crash.
    Sinon, l'UUID recherché semble être un UUID générique pour un serveur bluethooth (?) (cf : ici ).

    Citation Envoyé par Morceau choisi
    Hint: If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. However if you are connecting to an Android peer then please generate your own unique UUID.
    J'ai l'impression que l'appairage se perd, ou que l'UUID descriptif du dispositif appairé n'est pas bien stocké.

    Pour le coup, je ne pourrai pas beaucoup plus t'aider...
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  8. #8
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut
    veux tu que je te passe l'application entiere et tu fais tes propres teste ? car là je ne vois pas comment je peux te montrer le probleme :/

  9. #9
    Membre très actif
    Inscrit en
    Novembre 2006
    Messages
    371
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 371
    Par défaut
    Tenez voici le code source complet et merci d'avance:

    https://mega.nz/#!6AcxWJpB!94l931boh...h8b6iu_Vt44J84

Discussions similaires

  1. [Android] Plantage de l'application
    Par 23Reiji dans le forum Plateformes
    Réponses: 1
    Dernier message: 03/06/2015, 14h16
  2. Android : Laisser votre application faire vibrer votre portable
    Par nicolofontana12 dans le forum Contribuez
    Réponses: 2
    Dernier message: 05/08/2011, 16h47
  3. synchroniser android avec une application Desktop
    Par akram_dhiabi dans le forum Android
    Réponses: 3
    Dernier message: 04/04/2010, 17h28
  4. Réponses: 0
    Dernier message: 05/08/2009, 07h47
  5. Plantage d'application SDL sous Vista
    Par Scheb dans le forum SDL
    Réponses: 6
    Dernier message: 21/09/2008, 13h45

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