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

Update JShareModule.java #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -1,6 +1,8 @@
package cn.jiguang.share.reactnative;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.facebook.react.bridge.Arguments;
Expand All @@ -16,6 +18,12 @@

import java.util.HashMap;
import java.util.List;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.HttpURLConnection;
import java.io.IOException;
import java.io.InputStream;


import cn.jiguang.share.android.api.AuthListener;
import cn.jiguang.share.android.api.JShareInterface;
Expand Down Expand Up @@ -54,6 +62,29 @@ public JShareModule(ReactApplicationContext reactContext) {
super(reactContext);
}


public Bitmap imgUrlToBitmap(final String url) {
URL imgUrl = null;
Bitmap bitmap = null;
try {
imgUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) imgUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}


@Override
public String getName() {
return JSHARE_NAME;
Expand Down Expand Up @@ -127,7 +158,8 @@ public void share(final ReadableMap map, final Callback succeedCallback, final C
if (map.hasKey("imagePath")) {
shareParams.setImagePath(map.getString("imagePath"));
} else if (map.hasKey("imageUrl")) {
shareParams.setImageUrl(map.getString("imageUrl"));
Bitmap bitmap = imgUrlToBitmap(map.getString("imageUrl"));
shareParams.setImageData(bitmap);
} else if (map.hasKey("imageArray")) {
ReadableArray array = map.getArray("imageArray");
String[] imageArray = new String[array.size()];
Expand Down