bug fix :更新用户使用时长回调时间由10s更改为60s
This commit is contained in:
parent
fe601e0364
commit
53bc91c07a
|
|
@ -66,6 +66,7 @@ import com.yingmao.clash.util.ActivityResultLifecycle
|
||||||
import com.yingmao.clash.util.CommonUtils
|
import com.yingmao.clash.util.CommonUtils
|
||||||
import com.yingmao.clash.util.MarqueeTextView
|
import com.yingmao.clash.util.MarqueeTextView
|
||||||
import com.yingmao.clash.util.PayUtils
|
import com.yingmao.clash.util.PayUtils
|
||||||
|
import com.yingmao.clash.util.Utils
|
||||||
import com.yingmao.clash.util.startClashService
|
import com.yingmao.clash.util.startClashService
|
||||||
import com.yingmao.clash.util.stopClashService
|
import com.yingmao.clash.util.stopClashService
|
||||||
import com.yingmao.clash.view.RxToast
|
import com.yingmao.clash.view.RxToast
|
||||||
|
|
@ -384,7 +385,12 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher
|
||||||
MMKV.defaultMMKV().encode(BZYConstants.CONNECTID, dataInfo.data.id)
|
MMKV.defaultMMKV().encode(BZYConstants.CONNECTID, dataInfo.data.id)
|
||||||
val serviceIntent = Intent(requireContext(), ConnectionService::class.java)
|
val serviceIntent = Intent(requireContext(), ConnectionService::class.java)
|
||||||
serviceIntent.putExtra("receiver", resultReceiver)
|
serviceIntent.putExtra("receiver", resultReceiver)
|
||||||
requireContext().startService(serviceIntent)
|
val serviceRunning =
|
||||||
|
Utils.isServiceRunning(requireContext(), ConnectionService::class.java)
|
||||||
|
android.util.Log.i("AppStartupStatus","data::"+serviceRunning)
|
||||||
|
if(!serviceRunning){
|
||||||
|
requireContext().startService(serviceIntent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -994,4 +1000,13 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher
|
||||||
})
|
})
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
val serviceRunning =
|
||||||
|
Utils.isServiceRunning(requireContext(), ConnectionService::class.java)
|
||||||
|
if(serviceRunning){
|
||||||
|
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
|
||||||
|
requireContext().stopService(serviceIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ import com.yingmao.clash.fragment.AccelerateViewModel;
|
||||||
public class ConnectionService extends Service {
|
public class ConnectionService extends Service {
|
||||||
|
|
||||||
private static final String TAG = "TimerService";
|
private static final String TAG = "TimerService";
|
||||||
private static final long INTERVAL_MILLIS = 10000; // 10 秒
|
private static final long INTERVAL_MILLIS = 60000; // 60 秒
|
||||||
private Handler handler = new Handler();
|
private Handler handler = new Handler();
|
||||||
private Intent intent;
|
private Intent intent;
|
||||||
private Runnable runnable = new Runnable() {
|
private Runnable runnable = new Runnable() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.yingmao.clash.util
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.app.ActivityManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.media.MediaDrm
|
import android.media.MediaDrm
|
||||||
|
|
@ -286,5 +287,15 @@ object Utils {
|
||||||
v.requestLayout()
|
v.requestLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
|
||||||
|
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||||
|
val runningServices = manager.getRunningServices(Int.MAX_VALUE)
|
||||||
|
|
||||||
|
for (service in runningServices) {
|
||||||
|
if (serviceClass.name == service.service.className) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue