我有下一个代码:
class Printer{
Activity activity;
public Printer (Activity activity) {
this.activity = activity;
initializeBluetooth();
}
public boolean initializeBluetooth() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Context context = activity.getApplicationContext();
Toast toast = Toast.makeText(context, activity.getString(R.string.notSupportedBluetooth), 3000);
toast.show();
return false;
} else {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivityForResult(enableBtIntent, 0);
return false;
}
}
return true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println(resultCode);
if (resultCode == 0) {
System.out.println("one");
} else {
System.out.println("two");
}
}}
问题是onActivityResult,我知道它不能被调用,因为该类不是一个活动,所以我如何检查用户是否点击了蓝牙请求而不将我的类变成活动?activity.startActivityForResult(enableBtIntent, 0);
谢谢