Metodos de Intent para enviar email

Asked

Viewed 581 times

1

Could someone please clarify the following code:

Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
            intent.putExtra(Intent.EXTRA_TEXT, "Body of email");
            intent.setData(Uri.parse("mailto:[email protected]"));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

In setType("text/plain"); what the parameter and what the method itself would be?

How the puExtra(); and of setData();, are not similar methods?

What would be the addFlags();? What parameters can it receive?

1 answer

1

Okay, come on, come on:

1 - setType(): Defines an explicit MIME data type.
- This is used to create intents that only specify a type and not data, for example to indicate the type of data to return.
- This method automatically cleans all data that has been previously defined (for example, by setData (Uri)).

Note: The MIME match type in Android scope is case sensitive, unlike formal RFC MIME types. As a result, you should always write your MIME types in lower case, or use normalizeMimeType (String) or setTypeAndNormalize (String) to ensure that it is converted to lower case.

parameters:
type: String: The MIME type of the data to be processed by this.
return:
Returns the same Intent object, to chain multiple calls in a single instruction.

2 - putExtra and setData: No, they are not similar methods, see:
putExtra():

  • Adds extended data to Intent. The name should include a package prefix, for example, the app with.android.Contacts, would use names like "com.android.Contacts.Showall".

setData():

  • Define the data with which this input will operate from now on. This method automatically clears any type that was previously defined by setType (String) or setTypeAndNormalize (String).

3 - setFlags():
Defines special flags that control how this Intent will be treated. Most of the values here depend on the type of component that is being run by Intent, specifically the FLAG_ACTIVITY_* flags are all for use with Context.startActivity() and the FLAG_RECEIVER_ flags are all for use with Context.sendBroadcast ().

Behold Tasks and Back Stack for important information on how some of these options affect the behavior of your application.

no more is this and from what I can see it seems that you are starting now with programming for android, so follow some tips:

1 - learn English;
2 - Study man, that answer I translated from google Veloper console that was easily found when I requested "Intent.addflags" in the search field.

light and peace!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.