我試圖將圖像添加到我的Twitter共享意圖。我在一個班級中本地保存圖像,然後在另一個圖像中獲取圖像並嘗試附加到我的意圖。將圖像添加到Twitter共享意圖Android
這裏是我的代碼
private void shareTwitter(){
try {
FileInputStream fis;
fis = getActivity().openFileInput("photo.jpg");
Bitmap shot = BitmapFactory.decodeStream(fis);
File file = new File(MapView.path, "snapshot.jpg");
if(file.exists()){
Log.i("FILE", "YES");
}else{
Log.i("FILE", "NO");
}
Uri uri = Uri.parse(file.getAbsolutePath());
//Uri uri = Uri.parse("android.resource://com.gobaby.app/drawable/back");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("/*");
intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
intent.putExtra(Intent.EXTRA_TEXT, "Thiws is a share message");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
} catch (final ActivityNotFoundException e) {
Toast.makeText(getActivity(), "You don't seem to have twitter installed on this device", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
目前有在我的logcat也不例外我的應用程序只顯示舉杯說圖像加載失敗。
請問我做錯了什麼?
運行通過'調試run'一步一步,並檢查你的變量。 –
我應該檢查哪個變量?對於初學者來說這是正確的做法嗎?我檢查過是否找到了該文件。 –
你能成功保存任何內容到Twitter嗎? –