[英]Twitter sharing using Fabric SDK in android
I want to share the image and text on twitter using my App. 我想使用我的应用程序在Twitter上共享图像和文本。 I user Fabric SDK and follow the guidelines on their official website.
我使用Fabric SDK,并遵循其官方网站上的准则。 Problem is my image is not stored in phone storage and its a URL link.
问题是我的图像未存储在手机存储中,并且没有URL链接。 so when I pass that URL its not showing like FB sharing.
因此,当我传递该URL时,它不会像FB共享那样显示。
Below I have posted the Tried code for now. 下面,我已经发布了Tried代码。
private void shareViaTwitt() {
final String myUrlStr = "http://i.stack.imgur.com/2FCsj.png";
URL url;
Uri uri = null;
try {
url = new URL(myUrlStr);
uri = Uri.parse(url.toURI().toString());
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
TweetComposer.Builder builder = new TweetComposer.Builder(getContext())
.text("Hi this is Sample twitter sharing")
.image(uri);
builder.show();
}
Thank you. 谢谢。
/*In their official site has said need put file type uri that stored in
phone/SD storage. So Here I just save it and get that uri and then pass it to
fabric builder.*/
private void shareViaTwitt() {
final String myUrlStr = "http://i.stack.imgur.com/2FCsj.png";
TweetComposer.Builder builder = null;
try {
Bitmap bm = getBitmapFromURL(myUrlStr);
Uri uri = getImageUri(getContext(), bm);
builder = new TweetComposer.Builder(getContext())
.text("Sample Text")
.image(uri)
.url(new URL(""https://www.newurl.....));
builder.show();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
public static Bitmap getBitmapFromURL(String src) {
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.