我的应用程序拍照,我想在Instagram的分享。
My app take photos and I want to share in Instagram.
我的应用程序将图像保存在此目录中
My app save the image in this directory
File storagePath = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/tubagram");
现在我想要得到的最后一张照片我抽放利用这个code在Instagram的分享
Now I'm trying to get the last picture I taked to share in Instagram using this code
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[] {MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATE_TAKEN};
Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
if (c1.moveToFirst() ) {
Log.i("Teste", "last picture (" + c1.getString(0) + ") taken on: " + new Date(c1.getLong(1)));
}
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+Environment.getExternalStorageDirectory() + "/DCIM/Camera/tubagram/" + c1.getString(0)));
shareIntent.setPackage("com.instagram.android");
c1.close();
startActivity(shareIntent);
我收到此错误消息无法下载文件举杯。 这面包是由Instagram的发送。
I receive a Toast with this error message "Unable to download file". This Toast is sent by Instagram.
我试图用这个链接的例子 - 分享Instagram的的照片 - 但没有工作。
I tried to use this link example - share a photo in instagram - but didn't work.
请帮助我!
我解决我的问题。
我的camera.takePicture后添加此行。
I add this line after the camera.takePicture.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
这行做了一个刷新和手机后,认识到保存在手机中的新闻图片。
This line do a "refresh" and after the phone recognize the news photos saved in your phone.
和我做对我的方法的一些变化
And I made some changes on my method
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[] {
MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.TITLE, MediaStore.Images.ImageColumns.DATE_TAKEN
};
Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
if (c1.moveToFirst() ) {
Log.i("Teste", "last picture (" + c1.getString(1) + ") taken on: " + new Date(c1.getLong(2)));
}
Log.i("Caminho download imagem", "file://"+Environment.getExternalStorageDirectory()+ "/Tubagram/" + c1.getString(1) + ".png");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+Environment.getExternalStorageDirectory()+ "/Tubagram/" + c1.getString(1)+".png"));
shareIntent.setPackage("com.instagram.android");
c1.close();
startActivity(shareIntent);
和这个另一种方法我验证是否安装在手机上的Instagram的
And with this another method I verify if the Instagram is installed on the phone
private boolean verificaInstagram(){
boolean installed = false;
try {
ApplicationInfo info = getPackageManager().getApplicationInfo("com.instagram.android", 0);
installed = true;
} catch (NameNotFoundException e) {
installed = false;
}
return installed;
}