Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix Branch 0.10.9 "...exposed beyond app through Intent.getData() " at Android N #58

Merged
merged 3 commits into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Aug 12 07:48:35 CEST 2017
#Fri Jun 01 10:33:07 BRT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
34 changes: 31 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.RNFetchBlob">

<application
android:label="@string/app_name">
<!-- Required to access Google Play Licensing -->
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

<!-- Required to download files from Google Play -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Required to keep CPU alive while downloading files
(NOT to keep screen awake) -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Required to poll the state of the network connection
and respond to changes -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Required to check whether Wi-Fi is enabled -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!-- Required to read and write the expansion files on shared storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application android:label="@string/app_name">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>

</manifest>
</manifest>
33 changes: 28 additions & 5 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import android.util.SparseArray;

import com.facebook.react.bridge.ActivityEventListener;
Expand All @@ -24,6 +27,7 @@
import okhttp3.OkHttpClient;
import okhttp3.JavaNetCookieJar;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -105,10 +109,29 @@ public void run() {
@ReactMethod
public void actionViewIntent(String path, String mime, final Promise promise) {
try {
Intent intent= new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getReactApplicationContext().startActivity(intent);
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));

if (Build.VERSION.SDK_INT >= 24) {
// Create the intent with data and type
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uriForFile, mime);

// Set flag to give temporary permission to external app to use FileProvider
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
if (intent.resolveActivity(pm) != null) {
this.getReactApplicationContext().startActivity(intent);
}

} else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

this.getReactApplicationContext().startActivity(intent);
}
ActionViewVisible = true;

final LifecycleEventListener listener = new LifecycleEventListener() {
Expand Down Expand Up @@ -382,4 +405,4 @@ public void getSDCardDir(Promise promise) {
public void getSDCardApplicationDir(Promise promise) {
RNFetchBlobFS.getSDCardApplicationDir(this.getReactApplicationContext(), promise);
}
}
}
9 changes: 9 additions & 0 deletions android/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_files"
path="." />
<files-path
name="files-path"
path="." /> <!-- Used to access into application data files -->
</paths>