Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,27 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
// DownloadsProvider
else if (isDownloadsDocument(uri)) {

final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
String fileName = getFilePath(context, uri);
if (fileName != null) {
return Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
}

String id = DocumentsContract.getDocumentId(uri);
if (id.startsWith("raw:")) {
id = id.replaceFirst("raw:", "");
File file = new File(id);
if (file.exists())
return id;
}

final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);

return getDataColumn(context, contentUri, null, null);
// final String id = DocumentsContract.getDocumentId(uri);
// final Uri contentUri = ContentUris.withAppendedId(
// Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

// return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
Expand Down Expand Up @@ -152,6 +168,27 @@ public static String getImagePath(Context context, Uri uri){
return getDataColumn(context, uri, null, null);
}

public static String getFilePath(Context context, Uri uri) {

Cursor cursor = null;
final String[] projection = {
MediaStore.MediaColumns.DISPLAY_NAME
};

try {
cursor = context.getContentResolver().query(uri, projection, null, null,
null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}

/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,85 @@
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.Arguments;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import android.graphics.Bitmap;
import java.io.InputStream;

import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;

public class ShareModule extends ReactContextBaseJavaModule {


public ShareModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "ReactNativeShareExtension";
}

@ReactMethod
public void close() {
getCurrentActivity().finish();
}

@ReactMethod
public void data(Promise promise) {
promise.resolve(processIntent());
}

public WritableMap processIntent() {
WritableMap map = Arguments.createMap();

String value = "";
String type = "";
String action = "";

Activity currentActivity = getCurrentActivity();

if (currentActivity != null) {
Intent intent = currentActivity.getIntent();
action = intent.getAction();
type = intent.getType();
if (type == null) {
type = "";
}
if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(type)) {
value = intent.getStringExtra(Intent.EXTRA_TEXT);
public ShareModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "ReactNativeShareExtension";
}

@ReactMethod
public void close() {
getCurrentActivity().finish();
}

@ReactMethod
public void data(Promise promise) {
promise.resolve(processIntent());
}

public WritableArray processIntent() {
WritableArray dataArrayMap = Arguments.createArray();
Set<String> mediaTypesSupported = new HashSet<String>();
mediaTypesSupported.add("video");
// mediaTypesSupported.add("audio");
mediaTypesSupported.add("image");

String type = "";
String action = "";
String typePart = "";

Activity currentActivity = getCurrentActivity();

if (currentActivity != null) {
Intent intent = currentActivity.getIntent();
action = intent.getAction();
type = intent.getType();
if (type == null) {
type = "";
} else {
typePart = type.substring(0, type.indexOf('/'));
}
if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(type)) {
WritableMap dataMap = Arguments.createMap();
dataMap.putString("type", type);
dataMap.putString("value", intent.getStringExtra(Intent.EXTRA_TEXT));
dataArrayMap.pushMap(dataMap);
} else if (Intent.ACTION_SEND.equals(action) && ( "image/jpeg".equals(type) || "image/png".equals(type) || "image/jpg".equals(type)
|| "video/mp4".equals(type) || "video/3gp".equals(type) || "video/m4v".equals(type) || "video/mov".equals(type) || "video/mpeg".equals(type) || mediaTypesSupported.contains(typePart))) {
WritableMap dataMap = Arguments.createMap();
dataMap.putString("type", type);
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
dataMap.putString("value", "file://" + RealPathUtil.getRealPathFromURI(currentActivity, uri));
dataArrayMap.pushMap(dataMap);
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && ( "image/jpeg".equals(type) || "image/png".equals(type) || "image/jpg".equals(type) || mediaTypesSupported.contains(typePart))) {
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for (Uri uri : uris) {
WritableMap dataMap = Arguments.createMap();
dataMap.putString("type", type);
dataMap.putString("value", "file://" + RealPathUtil.getRealPathFromURI(currentActivity, uri));
dataArrayMap.pushMap(dataMap);
}
}
}
else if (Intent.ACTION_SEND.equals(action) && ("image/*".equals(type) || "image/jpeg".equals(type) || "image/png".equals(type) || "image/jpg".equals(type) ) ) {
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
value = "file://" + RealPathUtil.getRealPathFromURI(currentActivity, uri);

} else {
value = "";
}
} else {
value = "";
type = "";
}

map.putString("type", type);
map.putString("value",value);

return map;
}
}
return dataArrayMap;
}
}