0

I created an app that is shown in email sending apps list .

In a special app when user clicked on an email address , all of email sending apps apear on a list that my app is one of them and user can choose it.

I want to save email when user click on my app .

All things is fine but i dont know how i can get the emails from my app ?

I know other apps use this code :

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

But i dont know how access these data placed in Extra . i need to fetch mailto value only from top code.

How i can get mailto value now ?


Edit :

I have one app that shared many email addresses but i cant copy them . these emails are only links when i click them android apears all email sender apps . i wan to get this email one by one using my developed application and save them in a txt file .


EDIT 2 : I find a way to show my app in all other apps email sender list.i find out different applications used different methods to put extra content for sending email . for solve this problem and show your application in all of other applications email sending list i used many <intent-filter> in my AndroidManifest.xml like this :

Many apps used ACTION_VIEW method to send email . if you want show your application in this type of apps , you must use this code in your manifest file :

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="mailto" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

Another type of apps used ACTION_SEND to provide intent for calling email sender apps list . and if you want to show your app in these type of apps you must add this code to your AndroidManifest.xml file and your Activity tag : You can see 3 method to provide intent , i found these ways to show my app inside all apps email sending list maybe another methods exist and i dont know right now:

<intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="mailto"/>
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="text/*"/>
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="message/*"/>
        </intent-filter>

EDIT 3 : i used this code in my activity :

 bundle = intent.getExtras();
                if (bundle != null) {
                    for (String key : bundle.keySet()) {
                        Object value = bundle.get(key);
                        Log.d("Extra : ", String.format("%s %s (%s)", key,
                                value.toString(), value.getClass().getName()));
                    }
                }

And now i get log :

D/Extra :: android.intent.extra.EMAIL [Ljava.lang.String;@2244b9ca ([Ljava.lang.String;)

it shows i have one value in extra and its name is android.intent.extra.EMAIL but i cant get this value . i tested many ways !

SAYE
  • 1,247
  • 2
  • 20
  • 47
  • 1
    How do you know there is a bundle? It's not clear where you're getting that error. If there is only email it should work like I said below: String dataEmail = intent.getDataString(); – Michael Vescovo Mar 02 '17 at 04:09
  • `intent.getDataString()` and `intent.getData()` returned a null value . i checked both of them by `if` – SAYE Mar 02 '17 at 04:13
  • 1
    So does the bundle NOT return null? It's hard to know what the sending app is doing so we have to test all the things. – Michael Vescovo Mar 02 '17 at 04:14
  • i used this code `String type = intent.getType();` and it returned me this value `message/rfc822` . – SAYE Mar 02 '17 at 04:17
  • 1
    Did you try this since it says extra.EMAIL? String email = bundle.getString(EXTRA_EMAIL); – Michael Vescovo Mar 02 '17 at 04:18
  • yes it returns a `null` value. – SAYE Mar 02 '17 at 04:24
  • 1
    and the bundle? is that null? – Michael Vescovo Mar 02 '17 at 04:26
  • NO when i write this code : `bundle == null` return me `false` this means bundle is not null. if you see **Edit3** above i tested it before – SAYE Mar 02 '17 at 04:30
  • I test 3 another app right now all of them dont use `intent.GetData()` for sending email content and for all `intent.getData()` is a null value . i think when the apps used `ACTION_SEND` content sends using `bundle` – SAYE Mar 02 '17 at 04:37
  • 1
    ok. what action is being used? is it send or sendto? String action = intent.getAction(); Log.d(TAG, "onCreate: ACTION: " + action); – Michael Vescovo Mar 02 '17 at 04:38
  • 1
    see what bundle.toString() shows. maybe that will give you a clue. I'm not really sure at this point. If you have a bundle you should get able to get the data out. – Michael Vescovo Mar 02 '17 at 04:44
  • 1
    ok I updated my answer in response to edit 3. – Michael Vescovo Mar 02 '17 at 04:54
  • i used your answer for edit3 and i see in log something like this : `onCreate: BUNDLE STRING: Bundle[{android.intent.extra.EMAIL=[Ljava.lang.String;@2244b9ca}]` – SAYE Mar 02 '17 at 05:06
  • 1
    Ok well I think that is a question for a different post. I would suggest opening a new question about how to read data from that bundle. So it seems you know the key (EMAIL) but not the type. I don't think this is related anymore to your initial question. It's getting too hard to answer with so many comments. It will be difficult for others to follow... – Michael Vescovo Mar 02 '17 at 05:11
  • ok . thanks . if i create a new question i will share link here – SAYE Mar 02 '17 at 05:16
  • its my new question for continue of this question : http://stackoverflow.com/questions/42547616/retrive-android-intent-extra-email-value-from-bundle – SAYE Mar 02 '17 at 05:39

1 Answers1

1

You can do it like this. I just tested it and it works.

In a sample sending app do this after clicking a button or TextView: be careful not to use it on a link in a TextView using autolink as that breaks it. Just try it with a simple button to start.

// Create the text message with a string
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SENDTO);
sendIntent.setData(Uri.parse("mailto:test@gmail.com"));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "test subject");
sendIntent.putExtra(Intent.EXTRA_TEXT, "sent from first app");

// Verify that the intent will resolve to an activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(sendIntent);
}

Then in the receiving app manifest:

<!-- This activity handles "SEND" actions with text data -->
<intent-filter>
    <action android:name="android.intent.action.SEND"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:scheme="mailto"/>
</intent-filter>

And the receiving app Activity:

import static android.content.Intent.EXTRA_SUBJECT;
import static android.content.Intent.EXTRA_TEXT;

String dataEmail = intent.getDataString();
if (dataEmail != null) {
    Log.d(TAG, "onCreate: DATA EMAIL: " + dataEmail.substring(7));
}

String subject = intent.getStringExtra(EXTRA_SUBJECT);
Log.d(TAG, "onCreate: SUBJECT: " + subject);

String extraText = intent.getStringExtra(EXTRA_TEXT);
Log.d(TAG, "onCreate: EXTRA TEXT: " + extraText);

enter image description here

If you want it to work also on TextViews that have autolink then you need to add this to the manifest, however if you do that then only the email part will work. The subject will come back null.

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <data android:scheme="mailto"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

In response to edit 3 in the question If I pass a bundle in between my sample apps and use this:

for (String string :bundle.keySet()) {
    Log.d(TAG, "onCreate: VALUE: " + bundle.getString(string));
}

then it prints all the values out just fine. However I knew what values I put in (Strings) and I have no idea what the developer of whatever app you're using has used.

So to help with that you can print this:

Log.d(TAG, "onCreate: BUNDLE STRING: " + bundle.toString());

and at least when I try it I get details about what I put into it, and from there I can figure it out (if I didn't know).

Michael Vescovo
  • 3,741
  • 4
  • 32
  • 45
  • in reciving Activity i have Error for EXTRA_TEXT , EXTRA_EMAIL and EXTRA_SUBJECT . the error show this message for me : ` Can not resolve symbol EXTRA_TEXT ` – SAYE Mar 01 '17 at 12:32
  • if you can upload your tested project for me . thanks – SAYE Mar 01 '17 at 12:33
  • and your code is wrong manifest because you must use `` in Manifest . how you tested it ? – SAYE Mar 01 '17 at 12:36
  • 1
    Ok I adjusted the answer with the imports. Just add that and it should work. – Michael Vescovo Mar 01 '17 at 20:11
  • 1
    Ok I also changed it now so that it will work with mailto. If you do it exactly like this it will work. – Michael Vescovo Mar 01 '17 at 20:54
  • 1
    Ok now it even works with autolink. I hope this solves your problem as it took a while to get this working. Let me know if you're still having problems. – Michael Vescovo Mar 01 '17 at 21:16
  • this is incomplete again . when i use this manifest in my app . when user click send email in many apps i cant show my application in email senders list . and in many apps i can get mailo from `intent.getdata()` but its incomplete right now . i like design this part like gmail app that can show in all apps and get email and other parts successfully. – SAYE Mar 02 '17 at 03:01
  • 1
    Can you give an example of an app where this doesn't work? I can only go on the information you've provided. This works for the sample sending app I've described. Even if I click an email link from a webpage it still works. – Michael Vescovo Mar 02 '17 at 03:07
  • @MichaelVescobo pls download this app https://myket.ir/download?lang=en and open one app detail . scroll down and now you can see email address when you click on email you can see a list that your app is not here. the app size is : 7.5MB – SAYE Mar 02 '17 at 03:17
  • 1
    But did you at least test that it works as in my example? Create both the sending and receiving apps. Just create a new empty activity for each app and put the code in. You will see it works. Once you have this working try the other app again. Is there an example you can show me from the play store or some code from any other sending apps? – Michael Vescovo Mar 02 '17 at 03:27
  • I solved showing my app in another apps list and i put the way in **EDIT2** in question . but still i cant get the extra data for email address . i have not any code for sending anything . sending is happened from other apps and i only want to recive email address – SAYE Mar 02 '17 at 03:48
  • 1
    Ok I thought the problem wasn't with getting "detected" but rather getting the email from the intent once your app was open. Otherwise I would have said to add more filters. But good you finally got it working! – Michael Vescovo Mar 02 '17 at 03:52
  • For final problem please see my Question **EDIT3** . now i can see value existence but i can't grab it. – SAYE Mar 02 '17 at 03:53