为什么无法在类中解析此方法?这个类脱离了主要的 android 类。如果我将该方法放在主类中工作正常,但不能放在其他类中。
class blu {
public blu(){
}
public boolean comprobarBluetooth(Context context){
CharSequence text = "No tiene Bluetooth";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
//mirem si hi ha bluetooth al aparell
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter==null) {
//disparo un toast per informar
return false;
}else{
if (!mBluetoothAdapter.isEnabled()) {
//si està apagat obrim el dialeg per activarlo.
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}//SI startActivityForResult torna un OK faig return true, i executo el metode de buscar dispositivos
}
return true;
}
最佳答案
如果context
是您可以使用的Activity实例:
((Activity) context).startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
如果它不是 Activity 的实例,您将收到异常。
关于java - 无法解析此代码中的 startActivityforResults 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36721268/