我试图将图像添加到我的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吗? –