Try to share image with Automagic to send it via mail

Post your questions and help other users.

Moderator: Martin

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Try to share image with Automagic to send it via mail

Post by AMChris » 24 Feb 2018 18:40

Hi,

I hope you can help me with the following...

I want to select a text, link or image and share it with Automagic
so that it sends this info via mail to my account.

What I didn't find out is how to send an image as an attachment
with the information provided from the 'share intent'.
2018-02-24 19_37_31-Start.jpg
simple flow to send mail from share intent
2018-02-24 19_37_31-Start.jpg (14.55 KiB) Viewed 24416 times
I hope you can guide me in the right direction.

Thanks
Chris

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Try to share image with Automagic to send it via mail

Post by Desmanto » 25 Feb 2018 04:35

You can put Condition - Debug Dialog directly after trigger Send/Share Intent. Then try to share to Automagic intent. You can immediately see the file path is store in stream
stream_uri : file:///storage/emulated/0/Download/flows.xml
I don't know if Mail with Gmail can take the directly stream uri (with the file:// tag). If it can't use that, then you have to remove it using replace()

Code: Select all

filepath = replace(stream_uri, "file://", "");
Then use {filepath} as the attachment.

PS : You can do the same to any trigger to check what variable they provide.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Re: Try to share image with Automagic to send it via mail

Post by AMChris » 25 Feb 2018 10:03

Desmanto,
thanks for your reply, also for the tip with the replace statement :) .

My problem is that if I share an image via my photo app I get a stream uri like "content://media/external/images/media/194802"
and that doesn't seem to be a path to a file !?

The 'Mail with Gmail' action can't work with it.

Any ideas?

Thanks
Chris

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Re: Try to share image with Automagic to send it via mail

Post by AMChris » 25 Feb 2018 10:45

I did a web search for my problem and found a few articles like this one:
https://stackoverflow.com/questions/340 ... mediastore

It seems to be necessary to query a mediastore using a 'content resolver'!? :?

Code: Select all

public String getRealPathFromURI(Context context, Uri contentUri) {
  Cursor cursor = null;
  try { 
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
is this something that can be done in Automagic?

Thanks again
Chris

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Try to share image with Automagic to send it via mail

Post by Desmanto » 25 Feb 2018 12:02

I don't know much about how to use java in automagic, only can use few lines. But you wanna get the file path from the media provide. You can use Action Query Content Provider.

First you have to get the id from the images, simply using the same replace. Assume your stream_uri = "content://media/external/images/media/194802"

Code: Select all

id = replace(stream_uri, "content://media/external/images/media/", ""); //id = 194802
Action Query Content Provider
Content URI : content://media/external/images/media/
Projection : _data,_id
(just choose the ellipsis and check _id and _data)
Selection : _id = ?
Selection Arguments : {id}
Result Type : Single Value
Variable : result

{result} is the filepath to the image. Use this as the attachment. You can actually attach multiple files. But you have to change the Result Type to List or table. Then parse the file path to newList, use that list in listformat, comma delimited at the Files field in Mail with Gmail.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Re: Try to share image with Automagic to send it via mail

Post by AMChris » 25 Feb 2018 15:12

! MANY THANKS !
Thanks for your valuable advice. It worked and I managed to successfully send a mail with the image attached :D.

Now I try to figure out how to send/share a normal file as an attachment.
I think at the moment the encoding for the space is causing trouble!?
2018-02-25 15_59_19-Start.jpg
2018-02-25 15_59_19-Start.jpg (31.6 KiB) Viewed 24365 times
2018-02-25 16_00_42-Start.jpg
2018-02-25 16_00_42-Start.jpg (13.88 KiB) Viewed 24365 times

Does someone know if there is a simple way/function to convert it back to a valid path?
Of course I could use 'replace' but that would only be a workaround or much work to convert every possible character back.

Thanks again
Chris

P.S. when I am satisfied with the result I will share the flow

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Try to share image with Automagic to send it via mail

Post by Desmanto » 25 Feb 2018 17:27

Good to see it works. :)

Now that is the problem with special character. Spaces and other non standard character will be encoded to percent format %hh, just like using encodeURL(). Unfortunately, Automagic doesn't have decodeURL() to turn it back to original form (%20 become space). I ever indirectly suggest that it should be implemented.

Don't use replace, you are going to make a new map/list just to replace those character. (I almost do that). For meanwhile, you can use java function to convert it back.

Code: Select all

contentPath = "/storage/3835-3630/Music/Abba/Charts%2080s/79%20Abba%20-%20The%20day%20before%20you%20came.mp3";

path = callJavaStaticMethod("java.net.URLDecoder", "decode(java.lang.String)", contentPath);
replace the contentPath with the variable you work on. Any character that has passed thru encodeURL(), will be decoded back to its original form. (so it can be used properly as file path).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Re: Try to share image with Automagic to send it via mail

Post by AMChris » 26 Feb 2018 18:39

Thanks again!
Without your tips this wouldn't be possible for me.

I can now share a text, file or image and it will be sent to the preconfigured email address :D

User avatar
AMChris
Posts: 42
Joined: 22 Oct 2014 08:39

Re: Try to share image with Automagic to send it via mail

Post by AMChris » 27 Feb 2018 18:24

Now that the content provider query is working for the photo gallerie app,
I try to fine tune some of the special cases that are not working yet.

Sharing from the photo editor app gives me a stream_uri

Code: Select all

content://com.iudesk.android.photo.editor.provider/share/15196758705230
but starting a query for the content uri with:

Code: Select all

content://com.iudesk.android.photo.editor.provider/share/
gives me a 'Unknown URI' error.

The error occurs as soon as I click the 'ellipsis' for the Projection in the Action Query Content Provider dialog.

I don't think that the app from which I am sharing does something wrong because I can share images with other apps.
So there must be a trick to get this working - any ideas?
2018-02-27 19_11_43-Start.jpg
2018-02-27 19_11_43-Start.jpg (40.37 KiB) Viewed 24298 times
2018-02-27 19_14_05-Start.jpg
2018-02-27 19_14_05-Start.jpg (57.27 KiB) Viewed 24298 times

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Try to share image with Automagic to send it via mail

Post by Desmanto » 28 Feb 2018 15:56

Yes, I encounter the same problem too, specifically from Whatsapp. It seems the shared stream_uri is only the file, not the actual path. Sharing from Picsay pro, also have the same. But there are some difference.

If I share from Picsay, I can use Init Variable Image File on the stream_uri provided by Picsay, then it will loaded up fine. Of course I have to use another action Save Variable in Image File, save to a location and use that saved path as the attachment.

But if I share from Whatsapp, I will get permission denied. Something like this (I pass thru MiXplorer first)

Code: Select all

Permission Denial: opening provider com.whatsapp.MediaProvider from ProcessRecord{2a95c426 21221:com.mixplorer/u0a511} (pid=21221, uid=10511) that is not exported from uid 10160 
Using query content provider also won't work, same permission denied. It seems the app only allow the share uri to be used once only. If passed thru automagic, it become locked down again.

The whatsapp problem has been there since I haven't started using automagic. One of the update last year, started making Es File Explorer (at that time I still use EFE) can't save the image shared from Whatsapp. But MiXplorer can handle the uri fine (I am amazed, that's one of the reason I switch). If I share from Whatsapp to "Copy To" intent from MiXplorer, we can choose the save path and paste it there. The saved image is ok and file name is correct. If I saved using Automagic - Store as file, the file saved correctly, but file name is based on whatsapp provider id. So MiXplorer somehow can query the file name from Whatsapp provider. (don't know what is the trick, gonna ask the dev later).

Because MiX works, i try to use the Copy Action from it. Using the send broadcast, I include the stream_uri as the path. At Whatsapp, it doesn't work, and give the permission denied above. But If I share using Picsay, the file saved fine using Mixplorer Copy Action intent. So I can init image, save image, copy image from Picsay share. But I can't do the same from Whatsapp share. Shared directly to MiXplorer (without passing thru automagic), it can handle both perfectly. There must be something Mixplorer do under the hood, so It can handle those kind of content.

I am still investigating on this. For mean time, you can install MiXplorer. Share to the copy action first. Choose the location to temporary save the file. And then from Mixplorer, you can share one more time and choose Automagic intent received. The stream_uri share from MiXplorer is always the file:/// format
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply