由於我沒有得到任何方式發佈任何事情在Facebook上,所以我想另一種方式發佈到Facebook的文本。認爲它可能有幫助。順便說一下,它實際上並沒有共享文本。我將文本轉換爲圖像文件,而不是通過意圖發佈圖像。 這是我做到的。
TextView textView=new TextView(getBaseContext());
textView.setTag("textView");
View view=innerLayout.findViewWithTag("textView");
String SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_4444);
String path=SCREENSHOTS_LOCATIONS+ System.currentTimeMillis() + ".jpg";
final Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
System.out.println(bitmap.getHeight()+" "+bitmap.getWidth());
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(path);
System.out.println(sddir.getPath().toString());
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("abc", "Compress/Write failed");
}
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent=new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TITLE, "Title");
intent.putExtra(Intent.EXTRA_SUBJECT, "Extra Subject");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(path))); //optional//use this when you want to send an image
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(Intent.createChooser(intent, "send"), REQUEST_CODE);
你的問題是? –
@ Try_me34我想分享文本到Facebook。但我沒有找到辦法。如果你能幫助我? –