photo share intent in android

前端 未结 3 1704
庸人自扰
庸人自扰 2020-12-12 02:58
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType(\"image/*\");

Uri uri = U         


        
相关标签:
3条回答
  • 2020-12-12 03:25

    Try this

    Bitmap icon = mBitmap;
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/jpeg");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
        try {
            f.createNewFile();
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
        } catch (IOException e) {                       
                e.printStackTrace();
        }
        share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
        startActivity(Intent.createChooser(share, "Share Image"));
    

    Refer more links

    http://android-developers.blogspot.in/2012/02/share-with-intents.html

    Android Share Via Dialog

    Image post into facebook wall from android sdcard

    0 讨论(0)
  • 2020-12-12 03:28

    This is the solution I came up with: This function allows you to share to instagram, facebook or any other app if you know the package name. If the app is not installed it redirects to the Play Store. If you send "others" as parameters, you will display a list of apps that also support image sharing.

    shareImageIntent(mActivity,"image/*", "/storage/emulated/0/Pictures/Instagram/IMG_20150120_095603.jpg", "Instagram Sharing test. #Josh","com.instagram.android"); // parameters - for facebook: "com.facebook.katana" , to display list of other apps you can share to: "others"
    
     public void shareImageIntent(Activity a,String type, String mediaPath, String caption, String app){
            Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(app);
            if ((intent != null)||(app.equals("others"))){
    
                // Create the new Intent using the 'Send' action.
                Intent share = new Intent(Intent.ACTION_SEND);
    
                if(!app.equals("others"))
                    share.setPackage(app);
    
                // Set the MIME type
                share.setType(type);    
    
                // Create the URI from the media
                File media = new File(mediaPath);
                Uri uri = Uri.fromFile(media);
    
                // Add the URI and the caption to the Intent.
                share.putExtra(Intent.EXTRA_STREAM, uri);
                share.putExtra(Intent.EXTRA_TEXT, caption);
                // Broadcast the Intent.
                //startActivity(Intent.createChooser(share, "Share to"));
                a.startActivity(share);
                }
            else{
                intent = new Intent(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //intent.setData(Uri.parse("market://details?id="+"com.instagram.android"));
                intent.setData(Uri.parse("market://details?id="+app));
                a.startActivity(intent);            
                }   
            }
    
    0 讨论(0)
  • 2020-12-12 03:41

    You can not use Intent to post to Facebook. They have specifically blocked this. You have to either use their SDK or copy it to the clipboard and have the user paste it after the facebook interface opens. I am having this same problem.

    0 讨论(0)
提交回复
热议问题