• android 打电话程序的实现


    布局以及效果图片

    代码

    Strings.xml------------------------------------------------------------------------------------

    <?xml version="1.0" encoding="utf-8"?>
    <resources>

        <string name="app_name">day01_msm</string>
        <string name="action_settings">Settings</string>
        <string name="hello_world">Hello world!</string>
        <string name="phone_num">请输入手机号</string>
        <string name="phone_center">请输入内容</string>
        <string name="phone_btn">发送</string>

    </resources>

    --------------------------------------------------------------------------------------------------------------

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.day01_msm"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.WRITE_SMS"/>

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.day01_msm.SmsActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

    ------------------------------------------------------------------------------------------------------------

    package com.example.day01_msm;

    import java.util.ArrayList;

    import android.os.Bundle;
    import android.app.Activity;
    import android.app.PendingIntent;
    import android.content.Intent;
    import android.telephony.SmsManager;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;

    public class SmsActivity extends Activity {
     private Button button_viem;
     private EditText edit_phone;
     private EditText edit_sms;
     
     
     

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_sms);
           
           
            button_viem = (Button) findViewById(R.id.phone_btn);
            edit_phone = (EditText) findViewById(R.id.edit_num);
            edit_sms = (EditText) findViewById(R.id.edit_center);
           
            button_viem.setOnClickListener(new View.OnClickListener() {
       
       @Override
       public void onClick(View arg0) {
        String phone_num = edit_phone.getText().toString();
        String edit_content = edit_sms.getText().toString();
        SmsManager smsManager = SmsManager.getDefault();
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
          SmsActivity.this, 0, new Intent(), 0);
        ArrayList<String> contents = smsManager.divideMessage(edit_content);
        for (String c : contents) {
         smsManager.sendTextMessage(phone_num, null, c, pendingIntent, null);
        }
        Toast.makeText(SmsActivity.this, "正在发送短信", Toast.LENGTH_LONG).show();
        
       }
      });
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.sms, menu);
            return true;
        }
       
    }

  • 相关阅读:
    事件总线2
    微信小程序视频录制教程
    vue插件开发-toast
    云计算中的测试,可从哪些维度入手
    ES配置及FAQ
    Azkaban安装及问题
    python 反编译 compileall
    平凡利用redis进行数据读写的一种优化
    彻底弄懂Redis的内存淘汰策略
    c# 判断年龄精确到日
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3106595.html
Copyright © 2020-2023  润新知