新增运维拍照功能

serial
liuguijing 1 year ago
parent 0a2c25be18
commit 15a47c5f2c

@ -1,5 +1,6 @@
package com.xypower.mpmaster;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
@ -30,7 +31,9 @@ import com.xypower.mpmaster.sms.DownloadUtils;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@ -178,14 +181,37 @@ public class MainActivity extends AppCompatActivity {
// ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
// manager.restartPackage(context.getPackageName());
String ACTION_UPDATE_CONFIGS = "com.xypower.mpapp.ACT_UPD_CFG";
Intent intent = new Intent();
intent.setAction(ACTION_UPDATE_CONFIGS);
intent.putExtra("restart", 1);
// PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
sendBroadcast(intent);
// LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
// localBroadcastManager.sendBroadcast(intent);
// String ACTION_UPDATE_CONFIGS = "com.xypower.mpapp.ACT_UPD_CFG";
// Intent intent = new Intent();
// intent.setAction(ACTION_UPDATE_CONFIGS);
// intent.putExtra("restart", 1);
// // PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// sendBroadcast(intent);
//// LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
//// localBroadcastManager.sendBroadcast(intent);
// boolean photoOrVideo;
// photoOrVideo = true;
// List<Long> schedules = new ArrayList<>();
// long ts = System.currentTimeMillis() / 1000;
// long val = 0;
// val |= ((long) 1 << 16);
// val |= ((long) 255 << 8);
// val |= photoOrVideo ? 0L : 1L;
//
// schedules.add(Long.valueOf(val));
//
// Intent intent1 = new Intent();
// intent1.setAction(ACTION_TAKE_PHOTO);
// int cnt = schedules.size();
// intent1.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
// for (int idx = 0; idx < cnt; idx++) {
// intent1.putExtra(EXTRA_PARAM_SCHEDULE + idx, schedules.get(idx).longValue());
// }
// intent1.putExtra(EXTRA_PARAM_TIME, 0);
// intent1.putExtra(EXTRA_PARAM_TAKING_TIME, ts);
// sendBroadcast(intent1);
}
});

@ -15,7 +15,6 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import com.xypower.common.RegexUtil;
@ -40,6 +39,7 @@ public class SimUtil {
//自定义ACTION常数 作为广播的IntentFilter识别常数
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
public static String SMSTYPE = "smstype";
public static String SMSIFCORRECT = "smsifcorrect";
@ -61,12 +61,12 @@ public class SimUtil {
}
if (content.contains(SmsTypeEnum.REBOOT1.value())) {
ifmessageCorrect = true;
sendmessage = content + " OK";
sendtype = SmsTypeEnum.REBOOT1.value();
sendmessage = content + " OK";
} else if (content.contains(SmsTypeEnum.REBOOT2.value())) {
ifmessageCorrect = true;
sendmessage = content + " OK";
sendtype = SmsTypeEnum.REBOOT2.value();
sendmessage = content + " OK";
} else if (content.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
ifmessageCorrect = true;
String[] split1 = StringUtils.splitString1(content);
@ -408,8 +408,22 @@ public class SimUtil {
sendtype = SmsTypeEnum.TAKE_PHOTO.value();
ifmessageCorrect = true;
String[] split = StringUtils.splitString1(content);
Integer channel = StringUtils.convert2Int(split[0]);
sendmessage = getSendString(content, ifmessageCorrect);
if (split != null && split.length == 3) {
ifmessageCorrect = true;
Integer channel = StringUtils.convert2Int(split[0]);
Integer preset = StringUtils.convert2Int(split[1]);
Integer type = StringUtils.convert2Int(split[2]);
if (channel != null) {
boolean photoOrVideo;
if (type == 0) {
photoOrVideo = true;
} else {
photoOrVideo = false;
}
UpdateSysConfigUtil.takePhotoOrVideo(context, channel, preset, photoOrVideo);
}
sendmessage = getSendString(content, ifmessageCorrect);
}
} else if (content.contains(SmsTypeEnum.SET_HEART.value())) {
sendtype = SmsTypeEnum.SET_HEART.value();
String[] split1 = StringUtils.splitString1(content);
@ -438,7 +452,6 @@ public class SimUtil {
} else if (content.contains(SmsTypeEnum.GET_TP.value())) {
sendtype = SmsTypeEnum.GET_TP.value();
ifmessageCorrect = true;
String[] split = StringUtils.splitString1(content);
int tb = UpdateSysConfigUtil.getTB(context);
sendmessage = SmsTypeEnum.GET_TP.value() + "=" + tb;
} else if (content.contains(SmsTypeEnum.SET_PACKAGE.value())) {
@ -496,6 +509,7 @@ public class SimUtil {
}
private static String getSendString(String content, boolean ifmessageCorrect) {
String sendmessage;
String menssageBack = "";
@ -588,7 +602,8 @@ public class SimUtil {
}
//指定sim卡位置发送短信
public static void sendSms(Context mContext, int slot, String sender, String message, String value, boolean ifmessageCorrect) {
public static void sendSms(Context mContext, int slot, String sender, String message, String
value, boolean ifmessageCorrect) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
@ -686,7 +701,8 @@ public class SimUtil {
//申请该权限
public static void requestOnePermission(Activity activity, String permission, int permissionCode) {
public static void requestOnePermission(Activity activity, String permission,
int permissionCode) {
if (activity != null) {
activity.requestPermissions(new String[]{permission}, permissionCode);
}

@ -24,6 +24,17 @@ public class UpdateSysConfigUtil {
public static final String APP_ACTION_UPDATE_CONFIGS = "com.xypower.mpapp.ACT_UPD_CFG";
private static final String MASTER_ACTION_UPDATE_CONFIGS = "com.xypower.mpmaster.ACT_UPD_CFG";
//拍照的广播
public static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
public static final String EXTRA_PARAM_SCHEDULES = "Schedules";
public static final String EXTRA_PARAM_SCHEDULE = "Schedule_";
public static final String EXTRA_PARAM_TAKING_TIME = "TakingTime";
public static final String EXTRA_PARAM_TIME = "Time";
//创建运维配置文件文件夹
public static String buildAppDir(String packageurl) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
@ -243,7 +254,7 @@ public class UpdateSysConfigUtil {
}
//查询通道分辨率
public static HashMap<String,String> getChannelOSD(int channel) {
public static HashMap<String, String> getChannelOSD(int channel) {
HashMap<String, String> hashMap = new HashMap<>();
String path = getChannelDir(channel);
JSONObject jsonObject = JSONUtils.loadJson(path);
@ -313,4 +324,27 @@ public class UpdateSysConfigUtil {
context.sendBroadcast(intent);
}
public static void takePhotoOrVideo(Context context, long channel, long preset, boolean photoOrVideo) {
List<Long> schedules = new ArrayList<>();
long ts = System.currentTimeMillis() / 1000;
long val = 0;
val |= (channel << 16);
val |= (preset << 8);
val |= photoOrVideo ? 0L : 1L;
schedules.add(Long.valueOf(val));
Intent intent1 = new Intent();
intent1.setAction(ACTION_TAKE_PHOTO);
int cnt = schedules.size();
intent1.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
for (int idx = 0; idx < cnt; idx++) {
intent1.putExtra(EXTRA_PARAM_SCHEDULE + idx, schedules.get(idx).longValue());
}
intent1.putExtra(EXTRA_PARAM_TIME, 0);
intent1.putExtra(EXTRA_PARAM_TAKING_TIME, ts);
context.sendBroadcast(intent1);
}
}

Loading…
Cancel
Save