Browse Source

增加拨打运营商电话获取本机号码功能

weizhengliang 2 năm trước cách đây
mục cha
commit
f32d734233

+ 2 - 1
home/src/main/code/com/wdkl/ncs/android/component/home/activity/SmsReceivedActivity.kt

@@ -38,7 +38,8 @@ class SmsReceivedActivity : Activity() {
         tv_sms_reply.text = data
 
         //提取手机号
-        val regex = "((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9]))\\d{8}"
+        //val regex = "((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9]))\\d{8}"
+        val regex = "(1[3-9][0-9])\\d{8}"
         val phone = AppUtils.getMobileNumber(data, regex)
         edit_sms_phone.setText(phone)
 

+ 7 - 2
home/src/main/code/com/wdkl/ncs/android/component/home/service/PhoneStateReceiver.java

@@ -55,14 +55,14 @@ public class PhoneStateReceiver extends BroadcastReceiver {
             }
 
             //如果是运营商短信且是点击了号码查询才提示
-            if (SettingConfig.getOperatorNumber(context).equals(address) && Constants.Companion.getSmsCheck()) {
+            if (("10001".equals(address) || SettingConfig.getOperatorNumber(context).equals(address)) && Constants.Companion.getSmsCheck()) {
                 Intent smsIntent = new Intent(context, SmsReceivedActivity.class);
                 smsIntent.putExtra("address", address);
                 smsIntent.putExtra("sms_data", fullMessage);
                 smsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 context.startActivity(smsIntent);
             }
-            //Log.e(TAG, "received sms: " + fullMessage + ", address: " + address);
+            //Log.e(TAG, "received sms: " + fullMessage + ", address: " + address + ", check: " + Constant.smsCheck);
         } else if (action.equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
             String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
             DeviceChannel.calling = true;
@@ -126,6 +126,11 @@ public class PhoneStateReceiver extends BroadcastReceiver {
                     DeviceChannel.calling = false;
                 //}
             } else if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK) && extraIncomingNumber != null) {
+                //移动联通电信运营商号码默认为白名单
+                if ("10000".equals(extraIncomingNumber) || "10010".equals(extraIncomingNumber) || "10086".equals(extraIncomingNumber)) {
+                    return;
+                }
+
                 //通话中
                 //Log.d(TAG, "PhoneStateReceiver in call: " + extraIncomingNumber);
 

+ 19 - 0
home/src/main/code/com/wdkl/ncs/android/component/home/util/PhoneNumberDialogHelper.java

@@ -2,6 +2,8 @@ package com.wdkl.ncs.android.component.home.util;
 
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.content.Intent;
+import android.net.Uri;
 import android.telephony.SmsManager;
 import android.text.TextUtils;
 import android.view.Gravity;
@@ -33,6 +35,7 @@ public class PhoneNumberDialogHelper {
         EditText smsCmd = contentView.findViewById(R.id.edit_sms_cmd);
         TextView cancel = contentView.findViewById(R.id.btn_cancel_send);
         TextView send = contentView.findViewById(R.id.btn_send);
+        TextView call = contentView.findViewById(R.id.btn_call);
 
         phoneNum.setText("本机号码: " + ContactHelper.getPhoneNumber());
         operator.setText(SettingConfig.getOperatorNumber(activity));
@@ -72,6 +75,22 @@ public class PhoneNumberDialogHelper {
             }
         });
 
+        call.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                String number = operator.getText().toString();
+                if (!TextUtils.isEmpty(number)) {
+                    SettingConfig.setOperatorNumber(activity, number);
+
+                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
+                    activity.startActivity(intent);
+
+                    Constants.Companion.setSmsCheck(true);
+                    dismissCallDialog();
+                }
+            }
+        });
+
 
         dialog = builder.create();
         dialog.setCanceledOnTouchOutside(false);

+ 14 - 1
home/src/main/res/layout/phone_num_dialog_lay.xml

@@ -36,7 +36,8 @@
         <EditText
             android:id="@+id/edit_operator_number"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
+            android:layout_height="wrap_content"
+            android:inputType="number"/>
 
     </LinearLayout>
 
@@ -82,10 +83,22 @@
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:padding="4dp"
+            android:layout_marginLeft="10dp"
             android:gravity="center_horizontal"
             android:text="发送"
             android:textSize="16sp"
             android:textColor="@color/main_color"/>
+        <TextView
+            android:id="@+id/btn_call"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:padding="4dp"
+            android:layout_marginLeft="10dp"
+            android:gravity="center_horizontal"
+            android:text="拨打"
+            android:textSize="16sp"
+            android:textColor="@color/main_color"/>
     </LinearLayout>
 
 </RelativeLayout>