Create Bluetooth ON/OFF Switch
1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a Switch switch1.
For switch1 write text as 'Bluetooth', set width as match_parent, and set gravity as left.
3. Add onResume event and here use blocks to set the checked state of switch1 as per the state of bluetooth.
4. Create a more block setBluetooth<enable> and define it by putting following code in an add source directly block.
boolean isEnabled = bluetoothAdapter.isEnabled();
if (_enable && !isEnabled) {
bluetoothAdapter.enable();
} else if(!_enable && isEnabled) {
bluetoothAdapter.disable();
}
5. In switch1 onCheckChanged use block the setBluetooth Block to set the bluetooth on or off according to the checked state of switch1.
6. Save and run the project. Now on clicking the Switch, we can switch on or switch off the bluetooth in our device. Watch the videos below.
can you translate all these blocks into java code ?I went back to the old version. sketchware without.bluetooth, because my compiler started to produce non-existent errors in my old project , a large one , which I am working on .I will not adapt it to the new version , because I do not understand what he wants from me .
ReplyDeleteThe new class is:
Deletepublic void _setBluetooth(boolean _enable){
android.bluetooth.BluetoothAdapter bluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
boolean isEnabled = bluetoothAdapter.isEnabled();
if (_enable && !isEnabled) {
bluetoothAdapter.enable();
} else if(!_enable && isEnabled) {
bluetoothAdapter.disable();
}
}
It is used in switch on check changed listner as:
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_setBluetooth(isChecked);
}
});
New class have a error, this error is
Delete..........................
syntax error on token"void_setBluetooth",=expected after this token
...........................
How to I get?
DeleteThere should be space between void and _setBluetooth.
DeleteNow I space,but new have error.this error is
Delete..................................
syntax error on token "void", invalid AssignmentOperator
..................................
Please sir, Explain me.
DeleteThis comment has been removed by the author.
DeleteHow to make a online earning app.
ReplyDeletePlease find this
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteА можете подсказать , как кнопкой включить/отключить WiFi & включить/отключить GPS?
ReplyDeletePlease make send files using Bluetooth in SkeSketchw
ReplyDeleteHow to send 2bits number using blBluetoo ?
ReplyDeleteError have a code.
ReplyDeleteHello Developer, I need a tutorial, How to Make an Arduino Remote Control App via Bluetooth n Wifi with Skethware, I like to see Tutorials on YouTube and learn what you upload, I just want to learn. Thank you, Dev ...
ReplyDeleteHey develeode plz make a tutorial on Arduino control Like light on off,ultra Sonic sensor , wherever which can conttil the all tyoe arduArd sensors
ReplyDeletePlease make a tutorial how to send data through Bluetooth
ReplyDeleteWhat does mean the message "read failed, socket might closed or timeout, read ret: - 1". How to fix it?
ReplyDeleteThat is some problem with uuid.
Delete* Create a String variable UUID.
* Then use these codes on ListView item click or Bluetooth address click:
final android.bluetooth.BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(listmap.get((int)_position).get("address").toString());
final ParcelUuid[] uids;
if (android.os.Build.VERSION.SDK_INT >= 15){
uids = device.getUuids();
UUID = uids[0].toString();
}
else {
try {
Class cl = Class.forName("android.bluetooth.BluetoothDevice");
Class[] params = {};
java.lang.reflect.Method method = cl.getMethod("getUuids", params); Object[] args = {};
uids = (ParcelUuid[])method.invoke(device, args);
UUID = uids[0].toString();
} catch (Exception e) {
showMessage("Activation of getUuids() failed: " + e); }
}
Then use block
BluetoothConnect start connection with uuid UUID and address ..... with tag ...
mBluetoothAdapter cannot be resolved this message is coming
ReplyDeleteThe name of bluetooth adapter I used in codes is bluetoothAdapter. So change 'mBluetoothAdapter' to 'bluetoothAdapter' or vice versa.
Deleteandroid.bluetooth.BluetoothAdapter mBluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
DeleteYou can add this line.
This comment has been removed by the author.
DeleteActually the error comes is
Delete"read failed, socket might closed or timeout, read ret: - 1"
Then i put the above code given by you containing UUID. But it gives error message saying mBluetoothAdapter cannot be resolved.
Add this before the code
Deleteandroid.bluetooth.BluetoothAdapter mBluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
This comment has been removed by the author.
DeleteAfter writing your above code now again this message comes
Deleteread failed, socket might closed or timeout, read ret: - 1
Sir plz help
Delete1. ERROR in /storage/emulated/0/.sketchware/mysc/609/app/src/main/
ReplyDeletejava/com/my/newproject/MainActivity.java (at line 123)
if (_enable && !isEnabled) {
AnAnnnn
enable cannot be resolved to a variable
2, ERROR in /storage/emulated/0/.sketchware/mysc/60%/app/sre/main/
java/com/my/newproject/MainActivity. java (at line 125)
else if(!_enable && isEnabled) {
Annnnnn
enable cannot be resolved to a variable
2 problems (2 errors)
Hello sir can you make frequency analyzer app
ReplyDelete