Skip to content

Commit

Permalink
[WDB-028] - fixed an error `java.lang.SecurityException: Permission D…
Browse files Browse the repository at this point in the history
…enial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED`
  • Loading branch information
kirillzyusko committed Jul 10, 2020
1 parent 2f885ef commit 102e005
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions android/src/main/java/io/wifi/p2p/WiFiP2PManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pGroup;
import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.ResultReceiver;
Expand Down Expand Up @@ -253,12 +254,16 @@ public void onConnectionInfoAvailable(WifiP2pInfo info) {
@Override
public void invoke(Object object) {
if (forceToScanGallery) { // fixes: https://github.com/kirillzyusko/react-native-wifi-p2p/issues/31
reactContext.sendBroadcast(
new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"+ Environment.getExternalStorageDirectory())
)
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
final File file = new File(destination);
final Uri contentUri = Uri.fromFile(file);
scanIntent.setData(contentUri);
reactContext.sendBroadcast(scanIntent);
} else {
final Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
reactContext.sendBroadcast(intent);
}
}
}
}).execute();
Expand Down

0 comments on commit 102e005

Please sign in to comment.