如何使用我的Android应用程序将照片发送到Instagram?

前端之家收集整理的这篇文章主要介绍了如何使用我的Android应用程序将照片发送到Instagram?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序拍照,我想在Instagram上分享.

我的应用将图像保存在此目录中

File storagePath = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/tubagram");

现在,我正试图通过这段代码获取我在Instagram上分享的最后一张照片

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,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);

我收到一个Toast,显示错误消息“无法下载文件”.
这个Toast由Instagram发送.

我试图使用这个链接示例 – share a photo in instagram – 但没有用.

请帮帮我!!!

解决方法

解决了我的问题.

我在camera.takePicture之后添加了这一行.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

此行进行“刷新”,手机识别出手机中保存的新闻照片.

我对我的方法做了一些改变

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[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是否安装在手机上

private boolean verificaInstagram(){
    boolean installed = false;

    try {
        ApplicationInfo info = getPackageManager().getApplicationInfo("com.instagram.android",0);
        installed = true;
    } catch (NameNotFoundException e) {
        installed = false;
    }
        return installed;
    }

猜你在找的Android相关文章