"filters": [],
"versionCode": 1,
"versionName": "1.0",
- "outputFile": "ICSOS_V7_2110281634_release.apk"
+ "outputFile": "ICSOS_V8_2110282046_release.apk"
}
]
}
\ No newline at end of file
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+ <receiver android:name=".EndCallReceiver">
+ <intent-filter>
+ <action android:name="com.ic.alarm.action.END_CALL" />
+ </intent-filter>
+ </receiver>
</application>
</manifest>
\ No newline at end of file
--- /dev/null
+package com.ic.sos;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+
+import com.ic.iclooger.ICLogger;
+
+import java.util.Calendar;
+import java.util.Date;
+
+public class EndCallAlarmUtil {
+
+ public static final String ALARM_ACTION = "com.ic.alarm.action.END_CALL";
+ public static final int END_CALL_ID = 0x9988;
+
+
+ public static void cancelAlarm(Context context) {
+ Intent intent = new Intent(ALARM_ACTION);
+ PendingIntent pi = PendingIntent.getBroadcast(context, END_CALL_ID, intent, PendingIntent
+ .FLAG_CANCEL_CURRENT);
+ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ am.cancel(pi);
+ }
+
+ /**
+ * 毫秒,秒的话要换算
+ *
+ * @param context
+ * @param duration
+ */
+ public static void setAlarm(Context context, long duration) {
+ ICLogger.e("target duration==> " + duration);
+ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ Calendar calendar = Calendar.getInstance();
+ long intervalMillis = 0;
+ Date date = new Date();
+ calendar.setTimeInMillis(date.getTime() + duration);
+ Intent intent = new Intent(ALARM_ACTION);
+ PendingIntent sender = PendingIntent.getBroadcast(context, END_CALL_ID, intent, PendingIntent
+ .FLAG_UPDATE_CURRENT);
+ ICLogger.d("intervalMillis ==> " + intervalMillis);
+ //4.4以上的
+ long targetTime = calMethod(0, calendar.getTimeInMillis());
+ ICLogger.d("targetTime ==> " + targetTime);
+ am.setExact(AlarmManager.RTC_WAKEUP, targetTime, sender);
+ }
+
+
+ /**
+ * @param weekFlag 传入的是周几
+ * @param dateTime 传入的是时间戳(设置当天的年月日+从选择框拿来的时分秒)
+ * @return 返回起始闹钟时间的时间戳
+ */
+ private static long calMethod(int weekFlag, long dateTime) {
+ long time = 0;
+ //weekflag == 0表示是按天为周期性的时间间隔或者是一次行的,weekfalg非0时表示每周几的闹钟并以周为时间间隔
+ if (weekFlag != 0) {
+ Calendar c = Calendar.getInstance();
+ int week = c.get(Calendar.DAY_OF_WEEK);
+ if (1 == week) {
+ week = 7;
+ } else if (2 == week) {
+ week = 1;
+ } else if (3 == week) {
+ week = 2;
+ } else if (4 == week) {
+ week = 3;
+ } else if (5 == week) {
+ week = 4;
+ } else if (6 == week) {
+ week = 5;
+ } else if (7 == week) {
+ week = 6;
+ }
+ if (weekFlag == week) {
+ if (dateTime > System.currentTimeMillis()) {
+ time = dateTime;
+ } else {
+ time = dateTime + 7 * 24 * 3600 * 1000;
+ }
+ } else if (weekFlag > week) {
+ time = dateTime + (weekFlag - week) * 24 * 3600 * 1000;
+ } else {
+ time = dateTime + (weekFlag - week + 7) * 24 * 3600 * 1000;
+ }
+ } else {
+ if (dateTime > System.currentTimeMillis()) {
+ time = dateTime;
+ } else {
+ time = dateTime + 24 * 3600 * 1000;
+ }
+ }
+ return time;
+ }
+}
--- /dev/null
+package com.ic.sos;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+
+import com.android.internal.telephony.ITelephony;
+import com.ic.iclooger.ICLogger;
+
+import java.lang.reflect.Method;
+
+public class EndCallReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ endCall();
+ }
+
+ private void endCall() {
+ try {
+ Method method = Class.forName("android.os.ServiceManager")
+ .getMethod("getService", String.class);
+ IBinder binder = (IBinder) method.invoke(null, new Object[]{Context.TELEPHONY_SERVICE});
+ ITelephony telephony = ITelephony.Stub.asInterface(binder);
+ ICLogger.d("endCall...");
+ if (telephony != null) {
+ telephony.endCall();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e("error", e);
+ }
+ }
+
+}
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
-import android.os.IBinder;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.lifecycle.MutableLiveData;
-import com.android.internal.telephony.ITelephony;
import com.ic.iclooger.ICLogger;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
//开始准备超时
if (callDuration != 0) {
//需要按时挂断
- handler.removeCallbacks(endCallTask);
+ EndCallAlarmUtil.cancelAlarm(mContext);
ICLogger.d("set up end call task...");
- handler.postDelayed(endCallTask, callDuration * 1000);
+ EndCallAlarmUtil.setAlarm(mContext, callDuration * 1000);
}
callPhone(targetPhoneNum);
}
}
}
- //挂断电话,在挂断电话回调的地方,判断有没有必要进行下一次轮询
- private final Runnable endCallTask = this::endCall;
-
- private void endCall() {
- try {
- Method method = Class.forName("android.os.ServiceManager")
- .getMethod("getService", String.class);
- IBinder binder = (IBinder) method.invoke(null, new Object[]{Context.TELEPHONY_SERVICE});
- ITelephony telephony = ITelephony.Stub.asInterface(binder);
- ICLogger.d("endCall...");
- if (telephony != null) {
- telephony.endCall();
- }
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e("error", e);
- }
- }
-
public void callPhone(String phone) {
if (telephonyManager.getCallState() != CALL_STATE_IDLE) {
return;
-#Thu Oct 28 16:34:22 CST 2021
-VERSION_CODE=7
+#Thu Oct 28 20:46:51 CST 2021
+VERSION_CODE=8