X-4 - Intent
X-4 - Intent
Development
INTENT ?
Intent filters
Passing data
between
activities
INTENT
New activity
with results
Implicit
intents
Explicit
intents
Android uses Intent for communicating between the components of an Application and also from one
application to another application.
Intent are the objects which is used in android for passing the information among Activities in an
Application and from one app to another.
All these features take advantage of the most significant, use of Intents, i.e., launching new Activities
• Explicit Intents are typically used for launching new Activities within the same application
• Nothing in the Intent object other than the name of the Activity to be launched matters
All other fields (action, data, category) are null
Each implicit Intent contains information useful to the receiver for performing the job:
• Action: the job that the sender can require to perform
• Data: the data on which the job will run
• Category: the execution requirements (e.g., of being executed in a browser)
▪ The system determines which Activity is best to run based on the fields (e.g., action) of the implicit Intent.
▪ If more than one Activity can handle the Intent, a dialog for the user to select which app to use is displayed.
- It is possible to pass some parameters to the start Activity by adding them as extra content of the intent.
- Within the just-started Activity, you can inspect the received Intent by using the getIntent() method
▪ How to inform the system that an Activity can handle a specific type of implicit Intent.
▪ This can be done by advertising that a given Activity can manage a specific implicit Intent, i.e., by
associating the Activity with an Intent filter .
▪ An Intent filter:
• declares the capability of an Activity of receiving implicit Intents of a specific type.
• delimits the Intents an Activity can handle.
▪ As soon as the user is done with the called Activity, the result will be sent back to the first Activity.
▪ Along with the actual result, additional information is returned from the called Activity to the calling Activity!
▪ The request code originally sent by the calling Activity.
▪ A result code to notify that the operation in the called Activity has been successful, (you can Imagin it as HTTP status codes ).
▪ When the second Activity returns, the system invokes the onActivityResult() method on the calling Activity.
▪ The data are sent back to the calling Activity as an intent.
▪ The calling Activity uses different request codes to distinguish between different types of requests.
• When receiving a result, the calling Activity uses the request code to identify the provenance of the result.
▪ The request codes only makes sense for the calling Activity, while they do not have any particular meaning for the
called Activity.
▪ In case the called Activity is part of our application, we have to deal also with the problem of returning data to the
calling Activity.
▪ We need to:
• Perform the operation for which we launched the second Activity
• Pack the result into an Intent object
• Determine the result code
• Terminate the called Activity
✓ In the first application, add a new button that opens a new activity containing two input fields: one for the phone number and one for
the message body.
✓ When the user clicks "Submit," the second application should open, pre-filled with the phone number and message body.
Hints:
Create an implicit intent with the action Intent.ACTION_SENDTO. Set the data to a smsto: URI that includes the phone number
(intent.setData(Uri.parse("smsto:" + phoneNumber)) . You can also add the message body as an extra in the intent. This will allow the
system to launch an SMS application with the pre-filled information.
Ensure that you have the necessary permissions in your AndroidManifest.xml file. Add the following lines to request camera and SMS permissions:
App 1 : <uses-permission android:name="android.permission.CAMERA"/>
App 2: <uses-permission android:name="android.permission.SEND_SMS"/>
Run Your Project: After finishing your project, launch it on your emulator or mobile device.
Record Your Screen: Create a screen recording of your app in action. Please keep the recording to a maximum length of 60 seconds.
Submit Your Work: Fill out the form linked below with your information and upload the recorded video.
https://forms.gle/Kfw6GispBDH5NugW9