Question

I have been fighting with a problem all morning and thought I would ask here now.

I use the following code to attach 9 patch images to an email:

sendIntent.setType("image/png");

ArrayList<Uri> uris = new ArrayList<Uri>();

uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%05d", mAppBackgroundCurrentFile)) );

sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, "Email:"));

The problem is that when I get the email, the image is not the original 9 patch, but the version without the scale and padding markers.

I should get this result: Expected result attachment

But I get this instead: Result received

I suspect that the app processes the raw file before sending it?

Additional information:

I am now attempting to save the file to the SDCARD before attaching them to the email. Well, for some reason, even copying removes the scale and padding markers... I don't get it.

Here is my copy function I took from raw copy function.

private boolean copyToSDCard( int resourceID, String finalName )
{
    String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
    OutputStream out = null;

    try
    {
        InputStream in = getResources().openRawResource( resourceID );
        out = new FileOutputStream(extStorageDirectory + "/" + finalName + ".9.png");
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    }
    catch (Exception e)
    {
        Log.e("copyToSDCard", e.toString());
        e.printStackTrace();
    }

    return false;
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while((read = in.read(buffer)) != -1){
      out.write(buffer, 0, read);
    }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top