I have the next code:
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");
}
}}
The problem is the onActivityResult, i know it can not be called because the class is not an Activity, so how can i check if the user clicked yes or no to the bluetooth request with out turning my class to an activity??? activity.startActivityForResult(enableBtIntent, 0);
Thank you
Why are you doing this? Just include all of the bluetooth functionality in the
Activityclass… there is no need to create a separate class for this.Anyway, just copy and paste your
onActivityResultcode into yourActivityfile:It makes no sense to include
onActivityResultin yourPrinterclass, asonActivityResultwill be called for the callingActivity.