|
|
@ -4,12 +4,16 @@ package com.xypower.mpmaster.sms;
|
|
|
|
import android.Manifest;
|
|
|
|
import android.Manifest;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.Network;
|
|
|
|
import android.net.Network;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.telephony.SmsManager;
|
|
|
|
import android.telephony.SmsManager;
|
|
|
@ -18,10 +22,12 @@ import android.telephony.SubscriptionInfo;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
import com.xypower.common.RegexUtil;
|
|
|
|
import com.xypower.common.RegexUtil;
|
|
|
|
import com.xypower.mpmaster.MpMasterService;
|
|
|
|
import com.xypower.mpmaster.MpMasterService;
|
|
|
@ -35,6 +41,7 @@ import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -52,6 +59,8 @@ public class SimUtil {
|
|
|
|
|
|
|
|
|
|
|
|
public static String SMSIFCORRECT = "smsifcorrect";
|
|
|
|
public static String SMSIFCORRECT = "smsifcorrect";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static int mRequestCode = 1;
|
|
|
|
|
|
|
|
|
|
|
|
//短信解析
|
|
|
|
//短信解析
|
|
|
|
public static void analysisSMSInfo(final Context context, final Intent intent, final SmsMessage smsMessage) {
|
|
|
|
public static void analysisSMSInfo(final Context context, final Intent intent, final SmsMessage smsMessage) {
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage);
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage);
|
|
|
@ -686,6 +695,61 @@ public class SimUtil {
|
|
|
|
return smsMessageModel;
|
|
|
|
return smsMessageModel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void setSmsMessageRead(Context context, SmsMessage smsMessage) {
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Uri uri = Uri.parse("content://sms/inbox");
|
|
|
|
|
|
|
|
ContentResolver contentResolver = context.getContentResolver();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> smsIds = new ArrayList<>();
|
|
|
|
|
|
|
|
String[] projection = new String[]{"_id", "address", "person", "body", "date", "read",};
|
|
|
|
|
|
|
|
String selection = "date>" + Long.toString(smsMessage.getTimestampMillis() - 5000);
|
|
|
|
|
|
|
|
String sortOrder = null; // "date desc"
|
|
|
|
|
|
|
|
cursor = contentResolver.query(uri, projection, selection, null, sortOrder);
|
|
|
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
|
|
|
String smsBody = cursor.getString(3);
|
|
|
|
|
|
|
|
String smsRead = cursor.getString(5);
|
|
|
|
|
|
|
|
if (TextUtils.equals(smsMessage.getMessageBody(), smsBody) && TextUtils.equals("0", smsRead)) {
|
|
|
|
|
|
|
|
smsIds.add(Long.valueOf(cursor.getLong(0)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!smsIds.isEmpty()) {
|
|
|
|
|
|
|
|
uri = Uri.parse("content://sms/");
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
|
|
|
values.put("read", "1");
|
|
|
|
|
|
|
|
for (Long smsId : smsIds) {
|
|
|
|
|
|
|
|
// int rows = contentResolver.update(uri, values, "_id=?", new String[]{Long.toString(smsId)});
|
|
|
|
|
|
|
|
int rows = contentResolver.delete(uri, "_id=?", new String[]{Long.toString(smsId)});
|
|
|
|
|
|
|
|
if (rows == 1) {
|
|
|
|
|
|
|
|
Log.i("SMS", "Successfully");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contentResolver.notifyChange(uri, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
FilesUtils.closeFriendly(cursor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void clearSms(Context context) {
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Uri uri = Uri.parse("content://sms");
|
|
|
|
|
|
|
|
ContentResolver contentResolver = context.getContentResolver();
|
|
|
|
|
|
|
|
contentResolver.delete(uri, "_id>0", null);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取是哪个sim卡收到短信
|
|
|
|
//获取是哪个sim卡收到短信
|
|
|
|
private static int getSmsSlot(Bundle bundle) {
|
|
|
|
private static int getSmsSlot(Bundle bundle) {
|
|
|
|
int slot = -1;
|
|
|
|
int slot = -1;
|
|
|
@ -740,7 +804,7 @@ public class SimUtil {
|
|
|
|
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
|
|
|
|
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
|
|
|
|
// itSend.putExtra(SMSDATA, (Serializable) jsonArray);
|
|
|
|
// itSend.putExtra(SMSDATA, (Serializable) jsonArray);
|
|
|
|
//sendIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|
//sendIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, 0, itSend, 0);
|
|
|
|
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Intent itDeliver = new Intent(SMS_DELIVERED_ACTION);
|
|
|
|
// Intent itDeliver = new Intent(SMS_DELIVERED_ACTION);
|
|
|
|
//deliveryIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|
//deliveryIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|