First I think I should describe my problem: I want to do a BluetoothRequest for turning it on, but I don't want to create a new Activity. I want to keep it in the MainActivity and put the code in subclasses. How is this possible? Down is my own idea of how to do it, but it don't works.
I have the MainActivity and a BluetoothActivity. The following code is from BluetoothActivity:
public class Bluetooth extends Fragment{
private Context context;
private TextView textView;
private final int REQUEST_ENABLE_BT = 1;
private String BtName;
private String BtAddress;
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
public Bluetooth(Context context){
//constructor
this.context=context;
textView = new TextView(this.context);
}
public boolean bluetoothUnterstuetz(){
if(mBluetoothAdapter == null) {
//Device doesn't support Bluetooth
textView.setText("Device doesn't support Bluetooth");
}
return true;
}
public void bluetoothActivate(){
if(mBluetoothAdapter.getState()== BluetoothAdapter.STATE_ON){
textView.setText("Bluetooth already on.");
}
if(!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
((Activity) context).startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
((Activity) context).setContentView(textView);
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
textView.setText(resultCode);
Log.i("bluetooth", "called");
((Activity) context).setContentView(textView);
}
With extends Fragment nothing happens, also logcat is empty. With extends Activity, the app crashs after starting. When I test the App on my Phone, I get the BluetoothRequest and can Choose my answer but afterwards the ContentView shows nothing, also Logcat stays empty
Somebody knows how to get the Result?