Bonjour,
J'arrive à activer le bluetooth mais pas à le désactiver et ça commence à me rendre fou si vous pouviez m'aider
Voici mon code :
J'ai essayé de l'activer avec bt.enable(); Mais ça ne fonctionne pas.
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 import android.os.Bundle; import android.provider.MediaStore.Audio; import android.app.Activity; import android.content.Context; import android.view.*; import android.widget.*; import android.media.*; import android.telephony.*; import android.bluetooth.*; import android.content.*; public class MainActivity extends Activity implements View.OnClickListener{ Button b1,b2,b3,b4; LinearLayout llt; String send; AudioManager audio; BluetoothAdapter bt; Intent enableBtIntent,disableIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); llt= new LinearLayout(this); llt.setGravity(Gravity.TOP); llt.setOrientation(LinearLayout.VERTICAL); audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); bt = BluetoothAdapter.getDefaultAdapter(); enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); disableIntent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); TextView tv1=new TextView(this); tv1.setText("Controle du Bluetooth"); llt.addView(tv1); b3=new Button(this); b3.setText("Bluetooth ON"); b3.setOnClickListener(this); b3.setId(3); llt.addView(b3); b4=new Button(this); b4.setText("Bluetooth OFF"); b4.setOnClickListener(this); b4.setId(4); llt.addView(b4); setContentView(llt); } public void onClick(View v){ // Bluetooth if(v.getId()==3){ send=("Bluetooth activé"); if (!bt.isEnabled()) { startActivityForResult(enableBtIntent, BluetoothAdapter.STATE_TURNING_ON); } } if(v.getId()==4){ send=("Bluetooth désactivé"); if (bt.isEnabled()) { bt.disable(); } } TextView txt= new TextView(this); txt.setText(send); llt.addView(txt); } }
Acton56
Partager