In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how Android uses the Action and Data properties of Intent to click the button to jump to the interface of making phone calls and sending text messages. I hope you will get something after reading this article. Let's discuss it together.
Realize
Change the layout to LinearLayout, set it to vertical through android:orientation= "vertical" >, and then add the id attribute.
Then add two buttons and set the Id property and display text.
Then come to Activity. First, get two Button through ID.
Button buttonCall = (Button) findViewById (R.id.call); Button buttonSend = (Button) findViewById (R.id.send)
And because the two Button click event listeners are similar, all pull out a common click event listener object.
View.OnClickListener listener = new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (); / / convert view to Button Button button = (Button) v; / / according to button's id switch (button.getId ()) {/ / if you dial the phone button case R.id.call: / / set Action behavior property intent.setAction (intent.ACTION_DIAL) / / 123456789 after setting data is the default phone to be dialed: intent.setData (Uri.parse ("tel:123456789")); startActivity (intent); break; case R.id.send: / / set the behavior to send SMS intent.setAction (intent.ACTION_SENDTO); / / set to send to 10086 intent.setData (Uri.parse ("smsto:10086")) / / set the default sending content of SMS intent.putExtra ("sms_body", "official account: overbearing programmer"); startActivity (intent); break;}
Then set a click event listener on the button in OnCreate.
Complete sample code
Package com.badao.relativelayouttest;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;public class IntentActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_intent); Button buttonCall = (Button) findViewById (R.id.call); Button buttonSend = (Button) findViewById (R.id.send); buttonCall.setOnClickListener (listener); buttonSend.setOnClickListener (listener) } View.OnClickListener listener = new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (); / / convert view to Button Button button = (Button) v; / / according to button's id switch (button.getId ()) {/ / if you dial the phone button case R.id.call: / / set Action behavior property intent.setAction (intent.ACTION_DIAL) / / 123456789 after setting data is the default phone to be dialed: intent.setData (Uri.parse ("tel:123456789")); startActivity (intent); break; case R.id.send: / / set the behavior to send SMS intent.setAction (intent.ACTION_SENDTO); / / set to send to 10086 intent.setData (Uri.parse ("smsto:10086")) / / set the default SMS content intent.putExtra ("sms_body", "official account: overbearing programmer"); startActivity (intent); break;};}
Because phone calls and text messages are used, you need to declare these two permissions and open AndroidMainfest.xml.
After reading this article, I believe you have a certain understanding of "how Android uses the Action and Data properties of Intent to click the button to jump to the interface for making phone calls and sending text messages". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.