May 31, 2019 03:16 PM
(This post was last modified: Jun 1, 2019 07:52 AM by datguy.dev.)
Greetings,
I'm trying to learn and write an Android app using Android Studio for a project. Java is not my forte', but it is 100% required.
So I have an example activity going and trying to implement THIS bluetooth library. I got as far as "After intent to choose device activity and finish that activity. You need to check result data on onActivityResult":
But how do I check the results exactly? Where is requestCode, resultCode, and the intent data, in order to pass it along to that method? I get you could imagine it returning an array or a tuple of data to pass from:
But I can't seem to find any examples explaining that. Any help would be appreciated! 🤦♂
Figured it out.
The startActivityForResult() method will call the onActivityResult() method, but it just had to be outside the onCreate() method where the startActivityForResult() method is. 😶
I'm trying to learn and write an Android app using Android Studio for a project. Java is not my forte', but it is 100% required.
So I have an example activity going and trying to implement THIS bluetooth library. I got as far as "After intent to choose device activity and finish that activity. You need to check result data on onActivityResult":
PHP Code
<?php
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) {
if(resultCode == Activity.RESULT_OK)
bt.connect(data);
} else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) {
if(resultCode == Activity.RESULT_OK) {
bt.setupService();
bt.startService(BluetoothState.DEVICE_ANDROID);
setup();
} else {
// Do something if user doesn't choose any device (Pressed back)
}
}
}
But how do I check the results exactly? Where is requestCode, resultCode, and the intent data, in order to pass it along to that method? I get you could imagine it returning an array or a tuple of data to pass from:
PHP Code
<?php
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
But I can't seem to find any examples explaining that. Any help would be appreciated! 🤦♂
Figured it out.
The startActivityForResult() method will call the onActivityResult() method, but it just had to be outside the onCreate() method where the startActivityForResult() method is. 😶
