In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to make phone calls and send text messages in Andriod Studio". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to make phone calls and send text messages with Andriod Studio".
Create a project in Android Studio, and then create a Module named "IntentDial" in the project. To implement this example in the Module, the specific steps are as follows:
(1) add a layout under the res\ layout directory of the new Module
File shouji.xml, set the added layout manager to the relative layout manager, then add four text boxes to the layout manager to display the company information, and then add two ImageButton components, namely the call button and the send SMS button. The code is as follows:
Android:id= "@ + id/text2" android:text= Web site: http://www.mingrisoft.com" android:layout_marginTop= "10dp" android:layout_below= "@ + id/text1" / > android:id= "@ + id/text3" android:text= Corporate email: mingrisoft@mingrisoft.com "android:layout_below=" @ + id/text2 "/ > android:id=" @ + id/text4 " Android:text= "Technical Service Hotline: 0431-84978981" android:layout_below= "@ + id/text3" / > android:id= "@ + id/imageButton_sms" android:layout_toRightOf= "@ + id/imageButton_phone" android:src= "@ drawable/sms" / >
(2) modify the MainActivity.java file in onCreate (side)
Get the phone picture button and SMS map in the layout file in the
Slice buttons and set click event listeners for them, the code is as follows:
Package com.mingrisoft.intentdial;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.view.View;import android.view.WindowManager;import android.widget.Button;import android.widget.ImageButton;import android.widget.ImageView;public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.shouji) / / get phone picture button ImageButton imageButton = (ImageButton) findViewById (R.id.imageButton_phone); / / get SMS picture button ImageButton imageButton1 = (ImageButton) findViewById (R.id.imageButton_sms); imageButton.setOnClickListener (listener); / / set click event imageButton1.setOnClickListener (listener) for phone picture button; / / set click event} for SMS picture button
(3) the listener object, which is of type OnClickListener, is used in the above code. Therefore, to create the object in Activity and override its onClick () method, in this method, by determining the id that clicks the button, set the Action and Date for the two ImageButton components to make calls and send text messages, respectively, as follows:
Package com.mingrisoft.intentdial;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.view.View;import android.view.WindowManager;import android.widget.Button;import android.widget.ImageButton;import android.widget.ImageView;public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.shouji) / / get phone picture button ImageButton imageButton = (ImageButton) findViewById (R.id.imageButton_phone); / / get SMS picture button ImageButton imageButton1 = (ImageButton) findViewById (R.id.imageButton_sms); imageButton.setOnClickListener (listener); / / set click event imageButton1.setOnClickListener (listener) for phone picture button / / set click event for SMS picture button} / / create a listening event object View.OnClickListener listener = new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent () / / create Intent object switch (v.getId ()) {/ / judge case R.id.imageButton_phone according to the id of ImageButton component: / / if it is the phone picture button intent.setAction (intent.ACTION_DIAL); / / call dial panel intent.setData (Uri.parse ("tel:043184978981")) / / set the number to dial startActivity (intent); / / start Activity break; case R.id.imageButton_sms: / / if it is SMS picture button intent.setAction (intent.ACTION_SENDTO) / / call to send short message intent.setData (Uri.parse ("smsto:5554")); / / set the number intent.putExtra ("sms_body", "Welcome to Android!") to be sent; / / set the content of the message to be sent};}
(4) in the AndroidManifest.xml file, set the permissions that allow the application to make phone calls and send SMS messages, as shown below:
Screenshot of the running result:
At this point, I believe you have a deeper understanding of "how to make phone calls and send text messages in Andriod Studio". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.