Introduction to Intent in android

  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

What exactly can Android Intents do?

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

What exactly can Android Intents do?

2. Start a service

What exactly can Android Intents do?

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

What exactly can Android Intents do?

  • Invoke the system camera application and store the photos taken

What exactly can Android Intents do?

5. Get and cut pictures

  • Get and cut pictures

What exactly can Android Intents do?

  • Cut a specific picture

What exactly can Android Intents do?

6. Turn on the system recorder

  • Open the recorded video and save it locally

What exactly can Android Intents do?

  • 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

What exactly can Android Intents do?

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

What exactly can Android Intents do?

13. Open another program

What exactly can Android Intents do?

14. Turn on the recorder

Intent mi = new Intent(Media.RECORD_SOUND_ACTION);

startActivity (mi);

15. Pass parameters

  • Pass objects between pages

What exactly can Android Intents do?

  • The next page gets the passed data

WeekViewEvent weekEvent = (WeekViewEvent)

intent.getSerializableExtra("WeekEvent");

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326481759&siteId=291194637