Reputation: 1360
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","[email protected]", 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 !
Upvotes: 0
Views: 3508
Reputation: 3931
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:[email protected]"));
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);
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).
Upvotes: 2