Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Help me understand this Bluetooth library? (Intent)

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":

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. 😶


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by phisnNov 11, 2020 08:44 AM 1 166 Nov 11, 2020 08:44 AM
Last Post: HFDone
[.NET] by BarretSep 10, 2017 01:05 PM 16 914 Sep 10, 2017 01:05 PM
Last Post: Tsukiri
[.NET] by Hackedbyak47imaskidJul 1, 2012 10:09 AM 15 456 Jul 1, 2012 10:09 AM
Last Post: idb.