Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet34/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   30   31   32   33   34   35   36   37   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

21
CHAPTER 3: Activities
Intent Extra Data
Any intent can have extra data added to it that you can use to send data with it other than 
specified by the  subelement.
While you can use one of the various putExtra(...) methods to add any kind of extra data, 
there are also a couple of standard extra data strings sent by putExtra(String,Bundle). You 
can find the keys in the section “Intent Constituent Parts” in the online text companion.
Intent Flags
You can set special intent handling flags by invoking the following:
intent.flags = Intent. or Intent. or ...
Most of these flags specify how the intent gets handled by the Android OS. Specifically, flags 
of the form FLAG_ACTIVITY_* are aimed at activities called by Context.startActivity(..), 
and flags like FLAG_RECEIVER_* are for use with Context.sendBroadCast(...). The tables in 
the section “Intent Constituent Parts” in the online text companion show the details.
System Intent Filters
The system apps (that is, the apps already installed when you buy a smartphone) have intent 
filters you can use to call them from your app. Unfortunately, it is not that easy to guess how 
to call the activities from system apps, and relevant documentation is hard to find. A way out 
is to extract this information from their APK files. This is done for you for API level 26, and 
the result is listed in the online text companion in the section “The System Intent Filters.”
As an example, suppose you want to send an e-mail. Looking at the system intent table in 
the online text companion, you can find a lot of actions for PrebuiltGmail. Which one do 
we use? Well, first a general-purpose interface should not have too many input parameters. 
Second, we can also look at the action name to find something that seems appropriate. 
A promising candidate is the SEND_TO action; all that it apparently needs is a mailto: data 
specification. And as it happens, this is the action we actually need. Using an elaborated 
mailto:... URL allows us to specify more recipients, CC and BCC recipients, a subject, and 
even the mail body. However, you can also just use "mailto:master@universe.com" and add 
recipients, body, and so on, by using extra fields. So to send an e-mail, while possibly letting 
the user choose among several e-mail apps installed on a device, write the following:
val emailIntent:Intent = Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto","abc@gmail.com", null))
Caution For implicit intent filters, if the caller specifies a URI data part as in intent.data 
= , it might not be sufficient to specify just the scheme/host/port/path inside the 
filter declaration. Under these circumstances, you also have to specify the MIME type, as in 
mimeType="*/*". Otherwise, the filter possibly won’t match. This generally happens in a content 
provider environment since the content provider’s getType() method gets called for the 
specified URI and the result gets set as the intent’s MIME type.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling