Pro Android with Kotlin



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə34/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   30   31   32   33   34   35   36   37   ...   231
@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

Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   30   31   32   33   34   35   36   37   ...   231




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə