[英]Bluetooth from Service in android
在我的应用程序中,我使用的是BroadcastReceiver,它会在检查电话状态RINGING后触发服务类。在服务类中,我会在检查数据库中的状态标志后禁用Wifi和蓝牙功能。我可以更改Wifi状态;但是例外当我为蓝牙尝试同样的操作时会出现。
有人可以建议一种在服务内部使用BluetoothAdapter的方法吗?
DatabaseServic是我的服务类,这是我在logcat中收到的主要异常。
java.lang.RuntimeException:无法创建服务com.android.radiationreducer.DatabaseService:java.lang.NullPointerException
if(mBluetoothAdapter.isEnabled())
{
System.out.println("inside bluetooth iffffffffffffffffffffffffffffff");
mBluetoothAdapter.disable();
Toast.makeText(DatabaseService.this, "BLUETOOTH DISABLED", Toast.LENGTH_SHORT).show();
myDB.execSQL("INSERT INTO bluetoothflag VALUES ('"+RESET+"');");
myDB.delete("bluetoothflag", null, null);
myDB.execSQL("INSERT INTO bluetoothflag VALUES ('"+RESET+"');");
myDB.execSQL("INSERT INTO bluetoothflag VALUES ('"+SET+"');");
System.out.println("inside bluetooth ifffffffffendddddddddd");
}
请提出其他任何以编程方式关闭蓝牙的方法...
您正在服务中使用BluetoothAdapter! (而且有效...)
您的错误在代码中的其他地方:
java.lang.RuntimeException:无法创建服务 com.android.radiationreducer.DatabaseService:java.lang.NullPointerException
也许您忘记了将服务添加到清单(常见错误)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.