Activity by the interaction between Intent and system service call

I. Purpose
Through this experiment understanding between Android development framework core program components Activity through the principle of Intent interactive way to pass parameters and system control via Intent service call, and deepen understanding through three specific experimental content experiments.
II. Experimental conditions
1. already installed computer Android Studio is an integrated development environment (desktop, notebook available)
2.JAVA SDK1.8 above
3.Android SDK 7.0
4. virtual simulation device or a real machine (physical real machine still need a USB cable)
5. master the basic method of using an integrated development environment
6. proficiency in Java object-oriented programming language
III. experimental content
1. users enter a phone number, the phone call telephone call telephone call functions and procedures to achieve direct call function;
2. users enter a phone number and a short message content, calls android mobile phone short message sending function to send a short message and implement "bypass" SMS sending direct messages sent;
3. the user to enter a Web URL, android phone call the default browser implementations web browsing capabilities
4. experimental report writing

IV. Experimental procedure and experimental results demonstrate that
(a) the user to enter a phone number, the phone call telephone call program implements
1. Packing List permissions configuration

1. <?xml version="1.0" encoding="utf-8"?>
2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3. package="com.qiniu.dailcall">
4.
5. <uses-permission android:name="android.permission.CALL_PHONE"/>
6.
7. <application
8. android:allowBackup="true"
9. android:icon="@mipmap/ic_launcher"
10. android:label="@string/app_name"
11. android:roundIcon="@mipmap/ic_launcher_round"
12. android:supportsRtl="true"
13. android:theme="@style/AppTheme">
14. <activity android:name=".MainActivity">
15. <intent-filter>
16. <action android:name="android.intent.action.MAIN" />
17.
18. <category android:name="android.intent.category.LAUNCHER" />
19. </intent-filter>
20. </activity>
21. </application>
22.
23. </manifest>
增加了调用电话的权限<uses-permission android:name="android.permission.CALL_PHONE"/>

2. Layout settings

1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:orientation="vertical">
6.
7. <EditText
8. android:id="@+id/et_1"
9. android:layout_width="match_parent"
10. android:layout_height="wrap_content"
11. android:hint="请输入手机号"/>
12. <Button
13. android:id="@+id/btn_1"
14. android:layout_width="match_parent"
15. android:layout_height="wrap_content"
16. android:text="呼叫"
17. android:layout_marginTop="20dp"/>
18. </LinearLayout>
Set interface for linear layout. Vertical arrangement is android: orientation = "vertical". EditText add a phone number to the user input. Add a button, you can click on the dial.

Package com.qiniu.dailcall 1.;
2.
3. Import androidx.appcompat.app.AppCompatActivity;
4. Import androidx.core.app.ActivityCompat;
5. The Import android.Manifest;
6. The Import android.content.Intent;
. 7 . Import android.content.pm.PackageManager;
8. The Import android.net.Uri;
9. The Import android.os.Build;
10. The Import android.os.Bundle;
11. The Import android.view.View;
12. The Import Android .widget.Button;
13. Import android.widget.EditText;
14. a Import android.widget.Toast;
here implements two interfaces, by clicking a button listener class is a listener when the cursor exits the input telephone number input box class.
15. public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener {
16. EditText met_1;
17. Button mBtn_1;
18.
19. @Override
20. protected void onCreate(Bundle savedInstanceState) {
21. super.onCreate(savedInstanceState);
22. setContentView(R.layout.activity_main);
23. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE},1);
24. met_1=findViewById(R.id.et_1);
25. met_1.setOnFocusChangeListener(this);
26. mBtn_1=findViewById(R.id.btn_1);
27. mBtn_1.setOnClickListener(this);
28. }
29.
30. @Override
31. public void onClick(View v) {
String = met_1.getText dailnum 32. The () toString ();.
33. The IF (dailnum == null || dailnum.equals ( "")) {
34. The Toast.makeText (MainActivity.this, "Please enter your phone number ", Toast.LENGTH_SHORT) .Show ();
35. the}
parameters passed by the caller intent, so that the phone call by startActivity (intent) of the phone service
36. Intent intent = new Intent (Intent.ACTION_CALL , Uri. the parse ( "Tel:" + dailnum));
37. A iF (Build.VERSION.SDK_INT> = Build.VERSION_CODES.M) {
! iF 38. A (checkSelfPermission (Manifest.permission.CALL_PHONE) = PackageManager.PERMISSION_GRANTED) {
determines whether there call permission is not for the privileges
39. a ActivityCompat.requestPermissions (the this, new new String [] {} Manifest.permission.CALL_PHONE,. 1);
40. a}
41.} {the else
42. a return;
43. a}
44 is . startActivity (Intent);
45.}
Determine whether the telephone number, enter the phone number you did not prompt and friendly user interaction.
@Override 46. The
47. The public void onFocusChange (View v, boolean hasFocus) {
48. The IF (met_1.getText (). ToString () == "Please enter your phone number") {
49. The met_1.setText ( "" );
50.}
51.}
52.}

Guess you like

Origin www.cnblogs.com/wghbk/p/12080469.html