<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont

本文涉及的产品
转发路由器TR,750小时连接 100GB跨地域
简介: 类package online.geekgalaxy.layoutlearn;import android.Manifest;import android.

package online.geekgalaxy.layoutlearn;

import android.Manifest;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by jailman on 2017/9/18.
 */

public class login extends Activity {

    public void SendSMS(String PhoneNumber, String SMS) {
        SmsManager sm = SmsManager.getDefault();
        if (isPhoneNumberValid(PhoneNumber) && isWithin70(SMS)) {
            /**
             * 当两个判定条件都通过时发送短信,先构建一个PendingIntent对象并使用getBroadcast()广播
             * 然后将PendingIntent,短信,电话号码等内容传入SmsManager的sendTextMessage()方法中*/
            try {
                PendingIntent pi = PendingIntent.getBroadcast(login.this, 0, new Intent(), 0);
                sm.sendTextMessage(PhoneNumber, null, SMS, pi, null);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Toast.makeText(login.this, "短信发送成功", Toast.LENGTH_LONG).show();
        } else {
            if (!isPhoneNumberValid(PhoneNumber)) {
                if (!isWithin70(SMS)) {
                    Toast.makeText(login.this, "电话号码格式错误!短信内容超过70个字!请改正!!!", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(login.this, "电话号码格式错误!请改正!!!", Toast.LENGTH_LONG).show();
                }
            } else {
                if (!isWithin70(SMS)) {
                    Toast.makeText(login.this, "短信内容超过70个字!请改正", Toast.LENGTH_LONG).show();
                }
            }
        }
    }


    //判断短信内容是否超过70个字
    public static boolean isWithin70(String s) {
        return s.length() <= 70;
    }

    //判断电话号码的格式是否正确
    public static boolean isPhoneNumberValid(String phoneNumber) {
        boolean valid = false;
        /**
         * 两种电话号码格式
         * ^\\(? 表示可以以(开头
         * (\\d{3}) 表示后面紧跟3个数字
         * \\)? 表示可以以)继续
         * [- ]? 表示在上述格式后面可以使用选择性的“-”继续
         * (\\d{4}) 表示后面紧跟4个数字
         * [- ]? 表示在上述格式后面可以使用选择性的“-"继续
         * (\\d{4})$ 表示以4个数字结束
         * 综上所述:正确的电话号码的格式可以以下面等几种做为参考:
         * (123)456-78900 123-456-78900 12345678900 (123)-456-78900
         * */
        String expression01 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";
        String expression02 = "^\\(?(\\d{3})\\)?[- ]?(\\d{5})[- ]?(\\d{5})$";
        //创建Pattern对象
        Pattern p01 = Pattern.compile(expression01);
        //将Pattern作为参数传入Matcher,当做电话号码phoneNumber的正确格式
        Matcher m01 = p01.matcher(phoneNumber);
        Pattern p02 = Pattern.compile(expression02);
        Matcher m02 = p02.matcher(phoneNumber);
        valid = m01.matches() || m02.matches();
        return valid;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        //sms button
        final Button bomb = (Button) findViewById(R.id.button4);
        bomb.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String PN = "13xxxxxxx";
                String SMS = "我要用短信轰炸你!这个是安卓发短信功能!";
                SendSMS(PN, SMS);
            }
        });

        //call button
        final Button call = (Button) findViewById(R.id.button5);
        call.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri data = Uri.parse("tel:" + "13xxxxxx");
                intent.setData(data);
                if (ActivityCompat.checkSelfPermission(login.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    Toast.makeText(login.this, "Call permission denied!", Toast.LENGTH_LONG).show();
                    return;
                }
                startActivity(intent);
        }
    });



}
}


目录
相关文章
|
Web App开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
TCP洪水攻击(SYN Flood)的诊断和处理 Posted by  海涛  on 2013 年 7 月 11 日 Tweet1 ​1. SYN Flood介绍 前段时间网站被攻击多次,其中最猛烈的就是TCP洪水攻击,即SYN Flood。
1016 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
异步通信 对于BS(Browser-Server 浏览器)架构,很多情景下server的处理时间较长。 如果浏览器发送请求后,保持跟server的连接,等待server响应,那么一方面会对用户的体验有负面影响; 另一方面,很有可能会由于超时,提示用户服务请求失败。
779 0
|
Web App开发 前端开发 Java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
ZooKeeper 保证了数据的强一致性,  zk集群中任意节点(一个zkServer)上的相同znode下的数据一定是相同的。
815 0
|
Web App开发 大数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
                                                                               1.
1750 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
如何获取设备特征码、版本号、激活码?方式一 第一步:打开凯立德移动导航系统,进入地图界面,点击“查找”第二步:在查找页面以“快拼”的输入方式下,输入“AAAAAA”(6个A)
995 0
|
Web App开发 前端开发 关系型数据库
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
云服务器 ECS > Linux操作运维问题 > 应用配置 > linux系统关闭IPv6的方式 linux系统关闭IPv6的方式 IPv6被认为是IPv4的替代产品,它用来解决现有IPv4地址空间即将耗尽的问题。
1061 0
|
Web App开发 算法 Java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
(1)直接插入排序 [java] view plaincopy /** 直接插入排序 **/   /** 数组是引用类型,元素值将被改变 **/   public static void insertSort(i...
713 0
|
Web App开发 前端开发 Java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
org.apache.hadoop.hive.ql.metadata.HiveException: Unable to rename output from: hdfs://nameservice/user/hive/warehouse/om_dw.
748 0
|
Web App开发 监控 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
最近在监控中发现HiveServer2连接到zookeeper里的连接持续上涨,很奇怪,虽然知道HiveServer2支持并发连接,使用ZooKeeper来管理Hive表的读写锁,但我们的环境并不需要这些,我们已经关闭并发功能,以下是线上的配置,甚至把这些值都改成final了。
736 0