What is an Intent?
-
Android provides an Intent mechanism to assist in the interaction and communication between applications, or to put it more accurately, Intent can be used not only between applications, but also for the interaction between activities, services and broadcast receivers within applications.
-
Intent is a runtime binding (runtime binding) mechanism, which can connect two different components in the process of program running. Through Intent, your program can express a certain request or wish to Android, and Android will select the appropriate component to respond according to the content of the wish
-
Activity, service and broadcast receiver communicate through Intent
If Activity1 needs to communicate with Activity2, the two do not need to communicate directly, but use Intent as a bridge. Generally speaking, Intent is similar to an intermediary. If this article is useful to you, please pay attention to our WeChat public account AppCode.
What exactly can an Intent do?
1. Open the specified page
2. Start a service
3. Send a broadcast
Intent intent = new Intent();
intent.setAction("...");
Context.sendBroadcast (intent);
4. Using the system camera
-
Simply take a picture and get the picture
-
Invoke the system camera application and store the photos taken
5. Get and cut pictures
-
Get and cut pictures
-
Cut a specific picture
6. Turn on the system recorder
-
Open the recorded video and save it locally
-
Select the video resource in the mobile phone
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 5);
7. Make a call
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
Uri data = Uri.parse("tel://110");
intent.setData(data);
startActivity(intent);
8. Send SMS
Uri uri = Uri.parse("smsto:10086");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "Hello");
startActivity(intent);
9. Open the specified webpage
10. Operating apk
-
Install the apk:
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
-
uninstall apk
Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);
11. Go to the contact page
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);
12. Call the system editor to add contacts
13. Open another program
14. Turn on the recorder
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity (mi);
15. Pass parameters
-
Pass objects between pages
-
The next page gets the passed data
WeekViewEvent weekEvent = (WeekViewEvent)
intent.getSerializableExtra("WeekEvent");