0

I create a bitmap in my app and want to share it via email apps or Facebook using Intent.ACTION_SEND. the share window opens and gmail and yahoomail apps icon appear but no facebook or g+! I really doesn't know what's the problem. There is another problem that gmail app cannot attach the file (created from bitmap). I read a few similar questions but still I'm stocked. Help me please.

here is my code for sharing:

private  static File writePhotoPng(Bitmap data, String pathName) {
    File file = new File(pathName);
    try {

        file.createNewFile();
        // BufferedOutputStream os = new BufferedOutputStream(
        // new FileOutputStream(file));
        FileOutputStream os = new FileOutputStream(file);
        data.compress(Bitmap.CompressFormat.PNG, 100, os);
        os.flush();
        os.close();


    } catch (Exception e) {
        e.printStackTrace();
    }
    return file;
}

public static void ShareOnFb(Bitmap share, Activity activity, String emailSubject){
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    // EDIT:
    // !!! childish mistake. below line is correct !!! intent.setType("Image/*");
    intent.setType("image/*");
    //add data to intent, the receiving app will decide what to do with it.

    // email subject:
    if (emailSubject != null && !emailSubject.equals("")){
        intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    }



    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(writePhotoPng(share, "temp.png")));

    activity.startActivity(Intent.createChooser(intent, "Share on"));
}
Alireza Farahani
  • 2,238
  • 3
  • 30
  • 54

1 Answers1

0

after correcting my childish mistake (see EDIT part in question) and Using this code snippet I finally solved this problem.

if anybody knows whats the difference between using contentValue and my approach please share that with me.

Community
  • 1
  • 1
Alireza Farahani
  • 2,238
  • 3
  • 30
  • 54
  • help me here http://stackoverflow.com/questions/31847086/how-to-attach-jpg-or-png-file-to-gmail-or-facebook – Aditya Aug 06 '15 at 06:25