Skip to content

Unable to startPearDiscovery - Android 10 #101

@BRAVO68WEB

Description

@BRAVO68WEB

Env

Device Name: POCO F1
Android Version: 10
React Native Version: 0.74.2

Issue

I am not able to start peer discovery on Andorid 10. It is working on Android 13+

Code sample

  • Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission
               android:required="true"
               android:name="android.permission.ACCESS_COARSE_LOCATION"/>
   <uses-permission
           android:required="true"
           android:name="android.permission.ACCESS_WIFI_STATE"/>
   <uses-permission
           android:required="true"
           android:name="android.permission.CHANGE_WIFI_STATE"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />     
   <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
   <uses-feature
        android:name="android.hardware.wifi.direct"
        android:required="true" />
           
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
   <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"
        android:usesPermissionFlags="neverForLocation" />    
    <application
        android:usesCleartextTraffic="true"
        tools:targetApi="28"
        tools:ignore="GoogleAppIndexingWarning"/>
</manifest>
  • p2pconnection.ts
public constructor() {
    this.isInitialized = false;
    this.startedPeerDiscovery = false;
  }

  public init = async () => {
    if (this.isInitialized) {
      return;
    }
    try {
      await initialize().then(() => {
        console.log('WifiP2P initialized');

        this.isInitialized = true;
      });
      const cl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_COARSE_LOCATION',
        } as Rationale,
      );
      const fl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_FINE_LOCATION',
        } as Rationale,
      );
      const nwd = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.NEARBY_WIFI_DEVICES,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'NEARBY_WIFI_DEVICES',
        } as Rationale,
      );

      const abl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_BACKGROUND_LOCATION',
        } as Rationale,
      );

      console.log('Permissions', cl, fl, nwd, abl);
    } catch (e) {
      console.error(e);
    }
  };

  public startPeerDiscovery = async () => {
    if (!this.isInitialized) {
      console.error('WifiP2P not initialized');
      return;
    }
    if (this.startedPeerDiscovery) {
      return;
    }
    try {
      await startDiscoveringPeers().then(() => {
        this.startedPeerDiscovery = true;
        console.log('Peer discovery started');
      });
    } catch (e) {
      console.log(e);
    }
  };
  • Error Log
 LOG  WifiP2P initialized
 LOG  Permissions granted never_ask_again never_ask_again granted
 LOG  {"code": 0, "message": "Operation failed due to an internal error."}
 LOG  {"code": 0, "message": "Operation failed due to an internal error."}

Looks like ACCESS_COARSE_LOCATION and ACCESS_BACKGROUND_LOCATION is granted, but others are never_ask_again

Adb Logcat

logcat.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions