aboozaid / react-native-tethering

A React Native module for working with Wi-Fi and Hotspot. Compatible with Expo.
https://react-native-tethering.onrender.com/
MIT License
17 stars 2 forks source link

Feedback about Permissions in general and question about Hotspot #13

Closed ohtoyeyejke closed 1 year ago

ohtoyeyejke commented 1 year ago

Tested almost every function I could get my hands on at the moment and found out this:

<uses-permission android:name="android.permission.WRITE_SETTINGS"
    tools:ignore="ProtectedPermissions" /> 

does not really make the app have write setting permissions at load.

Instead, what worked for me, was to navigate to the permissions page using the below code that is given in the example folder here: example/src/HotspotScreen.tsx

async () => {
            try {
              await HotspotManager.openWriteSettings();
            } catch (error: any) {
              if (error instanceof TetheringError) {
                ToastAndroid.show(error.message, ToastAndroid.LONG)
              }
              console.log(error);

            }
          }

that way we prompt the user to enable the permissions himself and everything works smoothly after that.

As for other permissions like FINE / COURSE_LOCATION, again I faced the same problem with the log showing "Error UID [exampleUID] does not have FINE / COURSE_LOCATION permissions. To bypass this I used this code block :

import { PermissionsAndroid } from 'react-native';

async function requestMultiplePermissions() {
  try {
    const granted = await PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
    ]);
    if (
      granted['android.permission.ACCESS_FINE_LOCATION'] ===
        PermissionsAndroid.RESULTS.GRANTED &&
      granted['android.permission.ACCESS_COARSE_LOCATION'] ===
        PermissionsAndroid.RESULTS.GRANTED
    ) {
      console.log('Location permissions granted');
      // Call the desired function here
    } else {
      console.log('Location permissions denied');
    }
  } catch (err) {
    console.warn(err);
  }
}

@aboozaid Overall, if you bypass the permissions "errors" (which ain't exactly errors per se), everything seems to work as intended. I would like to thank you for publishing this, after such short notice.

I only have one question, which is really important to me and I think many others that will use this module.

Can you add a function in the example where the SSID and Password of the enabled Hotspot are predefined by the programmer, so the user doesn't have to navigate to it's page and put them manually after opening it through your module? Adding an example of it would be great!

Thank you for your time and I hope this proves to be helpful.

aboozaid commented 1 year ago

Starting from android 8 and above you cannot change SSID & Password of a hotspot. If you want a local connection between two devices you could use BLE with Hotspot as ShareIt do just to share these credentials to the other devices without letting the user types them.

ohtoyeyejke commented 1 year ago

Thank you for the fast reply!

aboozaid commented 1 year ago

Please close the issue if you don't have any other questions.