DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • How to Build a React Native Chat App for Android
  • Using Jetpack Compose With MVI Architecture
  • Implementing SOLID Principles in Android Development

Trending

  • Apple and Anthropic Partner on AI-Powered Vibe-Coding Tool – Public Release TBD
  • The End of “Good Enough Agile”
  • Agile’s Quarter-Century Crisis
  • Creating a Web Project: Caching for Performance Optimization
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Android SMS popup - Part Four: Implicit Intents

Android SMS popup - Part Four: Implicit Intents

By 
Tony Siciliani user avatar
Tony Siciliani
·
Oct. 05, 22 · Interview
Likes (1)
Comment
Save
Tweet
Share
13.8K Views

Join the DZone community and get the full member experience.

Join For Free

in  part one  , we captured sms messages using a broadcastreceiver. in , among a set of options, we chose to pass the needed sms information (sender, message and timestamp) as a serializable 'popmessage' object from the background to the foreground alert dialog that we constructed in :



in this last section, we will complete this basic application by handling the user actions through button clicks. there are two actions the user may perform:

  1. close the sms popup window once the message is read
  2. choose to respond to it using his favorite sms program.



we used  intents  in the previous parts of this series, as  asynchronous messages  to pass data between components:


    // in our broadcastreceiver class, we're passing the
    // sms message pop_msg to the popsmsactivity, i.e. our ui.
     intent.setclass(context, popsmsactivity.class);
     intent.setflags(intent.flag_activity_new_task);
     intent.putextra("msg", pop_msg);
     context.startservice(intent);



the above code uses an  explicit intent  , i.e an intent that indicates a particular class (  popsmsactivity  ) to pass data to. it is basically a direct call to another component (service, activity...). but intents can also be used to send messages to the android system so that the latter can determine what course of action to take.


 implicit  intents  do not designate  a specific class  which should be called by the system, but  the  action  which we would like to be performed by the system. how does android know which component(s) to call in order to perform that action? because those applications/components that can handle the action have previously registered themselves in the system. but how did they do that? the same way we did with our custom sms receiver in our application's manifest in part one of this series:


<!-- incoming sms messages can be intercepted by the smsreceiver class -->
<receiver android:name="com.ts.pop.sms.smsreceiver">
  <intent-filter android:priority="999" android:exported="true">
    <action android:name="android.provider.telephony.sms_received" />
  </intent-filter>
</receiver>



by using an  intent-filter  , we indicated to the android system that our application was a candidate for handling the sms_received event.  intent filters  are how components declare their capabilities so that other components can use them. android will look at the action, data, and category of the intent as part of its  intent resolution  process.


a given component can declare any number of intent filters, corresponding to the number of actions it can potentially handle. if a component does not have intent-filters, it can only respond to  explicit  intents. when there are several components that have the same intent filters, android will present the user with a list to choose from.


what the  smsreply()  method below is doing, is asking android to bring up any mms-sms program it can find on the phone :


     /***/
    private void smsreply(string sender, string body){
    	intent sendintent = new intent(intent.action_view);
    	sendintent.putextra("address", sender);
    	sendintent.putextra("sms_body", body);
    	sendintent.settype("vnd.android-dir/mms-sms");
    	startactivity(sendintent);
    	this.finish(); // close this activity now
    }



this is what it looks like on the phone, once the "reply" button is clicked and the sms program (second screen) is brought up automatically to send a response:




the gohome(), sweet home method called on closing the dialog, simply takes the user back to the phone home screen :


     /***/
    private void gohome(){
    	intent intent = new intent(intent.action_main);
        intent.addcategory(intent.category_home);
	intent.setflags(intent.flag_activity_new_task);
	startactivity(intent);
	this.finish();
    }



that's it. we now have our first working version of an sms popup application, and we can start building whatever new features we might think of on top of it.

here's  one example  of what can be done, by adding the list of phone contacts, sounds, and a settings screen.


source:  tony's blog  .

Intent (military) Android (robot) SMS

Opinions expressed by DZone contributors are their own.

Related

  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • How to Build a React Native Chat App for Android
  • Using Jetpack Compose With MVI Architecture
  • Implementing SOLID Principles in Android Development

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!