connectivity-samples
connectivity-samples copied to clipboard
App crashes on API 17,18
i Changed the minsdk and targeted sdk to 17 ...then i run it on API 17 it runs and asks to turn on Bluetooth when turned on the app flashes out. I tried to read stack and found this Please answer it in first priority Thanks in advance.
java.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager at com.example.android.bluetoothadvertisements.MainActivity.onCreate(MainActivity.java:44) When i opened the file it was pointing towards this line if (mBluetoothAdapter.isMultipleAdvertisementSupported())
https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html
get a BluetoothAdapter representing the local Bluetooth adapter, when running on JELLY_BEAN_MR1 and below, call the static getDefaultAdapter() method; when running on JELLY_BEAN_MR2 and higher, call getAdapter().
the full stack is here please guide me through it also thanks. ava.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager at com.example.android.bluetoothadvertisements.MainActivity.onCreate(MainActivity.java:44) at android.app.Activity.performCreate(Activity.java:5122) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365) at android.app.ActivityThread.access$600(ActivityThread.java:156) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:153) at android.app.ActivityThread.main(ActivityThread.java:5336) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method)
update the code to some about like that, in order to handle the depreciated API:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
} else {
/** the message says, there is no BluetoothManager - while the docs say static access */
mBluetoothAdapter = (BluetoothAdapter) BluetoothManager.getDefaultAdapter();
}
thanks a lot dear