Changed Bluetooth to insecure mode

This commit is contained in:
Ziver Koc 2015-02-18 16:51:42 +01:00
parent f9a8495461
commit 0300cf55c1
4 changed files with 14 additions and 8 deletions

View file

@ -21,12 +21,12 @@ public class BluetoothClient extends Thread {
this.msgHandler = msgHandler;
// Get a BluetoothSocket to connect with the given BluetoothDevice
socket = device.createRfcommSocketToServiceRecord(UUID.fromString(service_uuid));
socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(service_uuid));
//socket = device.createRfcommSocketToServiceRecord(UUID.fromString(service_uuid));
// Fallback
//socket = (BluetoothSocket)device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(device,1);
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
// Connect the device through the socket. This will block until it succeeds
try {
socket.connect();
} catch (IOException e){

View file

@ -25,7 +25,8 @@ public class BluetoothServer extends Thread {
// MY_UUID is the app's UUID string, also used by the client code
BluetoothAdapter adapter = BluetoothUtil.getAdapter();
serverSocket = adapter.listenUsingRfcommWithServiceRecord(service, UUID.fromString(service_uuid));
serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord(service, UUID.fromString(service_uuid));
//serverSocket = adapter.listenUsingRfcommWithServiceRecord(service, UUID.fromString(service_uuid));
}
public void run() {

View file

@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import com.ericsson.uecontrol.gui.MainActivity;
import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.Main;
import java.util.ArrayList;
import java.util.List;
@ -17,13 +18,16 @@ import java.util.UUID;
public class BluetoothUtil {
private static final Logger log = Logger.getLogger(BluetoothUtil.class);
public static final int BT_ENABLE_REQUEST_CODE = 1501;
public static final int BT_DISCOVERABLE_REQUEST_CODE = 1502;
public static BluetoothAdapter getAdapter() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null) {
if (!mBluetoothAdapter.isEnabled()) {
// Send Enable Bluetooth intent
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
((Activity) MainActivity.getContext()).startActivityForResult(enableBtIntent, 1515);
MainActivity.getContext().startActivityForResult(enableBtIntent, BT_ENABLE_REQUEST_CODE);
}
}
else
@ -117,6 +121,6 @@ public class BluetoothUtil {
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
MainActivity.getContext().startActivity(discoverableIntent);
MainActivity.getContext().startActivityForResult(discoverableIntent, BT_DISCOVERABLE_REQUEST_CODE);
}
}

View file

@ -1,6 +1,7 @@
package com.ericsson.uecontrol.gui;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -51,7 +52,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
/* Static Data */
private static UeControlExecutor executor;
private static int uid;
private static Context context;
private static Activity context;
@Override
@ -318,5 +319,5 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
public static int getUID(){
return uid;
}
public static Context getContext(){return context;}
public static Activity getContext(){return context;}
}