Skip to content

Instantly share code, notes, and snippets.

@winnerawan
Created July 2, 2024 14:32
Show Gist options
  • Select an option

  • Save winnerawan/18b3daa60798f2dd4a757ad6bd72179d to your computer and use it in GitHub Desktop.

Select an option

Save winnerawan/18b3daa60798f2dd4a757ad6bd72179d to your computer and use it in GitHub Desktop.
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class ProxyStatusEvent : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.e("LOG", "server on receive ${intent?.getStringExtra("value")}")
callback?.onStarted()
}
var callback: ProxyStatusEventCallback? = null
interface ProxyStatusEventCallback {
fun onStarted()
}
}
//spl
private var myReceiver: ProxyStatusEvent? = null
private var myReceiverIsRegistered: Boolean = false
override fun onResume() {
super.onResume()
if (!myReceiverIsRegistered) {
ContextCompat.registerReceiver(this, myReceiver, IntentFilter(PowerTunnelService.BROADCAST_STARTED), ContextCompat.RECEIVER_NOT_EXPORTED)
myReceiver?.callback = this
myReceiverIsRegistered = true;
}
}
override fun onPause() {
super.onPause()
if (myReceiverIsRegistered) {
unregisterReceiver(myReceiver);
myReceiverIsRegistered = false;
}
}
override fun onStarted() {
if (getAd(this@SplashActivity).splash.interstitial_.isEnable) {
if (!getAd(this@SplashActivity).splash.interstitial_.isMediation) {
Handler().postDelayed({
showInterstitial()
}, 2000)
} else {
Handler().postDelayed({
showInterstitialMediationSplash()
}, 2000)
}
} else {
launchBrowserActivity()
}
}
//spl_create
myReceiver = ProxyStatusEvent()
ContextCompat.registerReceiver(this, myReceiver, IntentFilter(PowerTunnelService.BROADCAST_STARTED), ContextCompat.RECEIVER_NOT_EXPORTED)
myReceiver?.callback = this
myReceiverIsRegistered = true
Dohp(this).startTunnel()
//main
override fun onResume() {
super.onResume()
try {
if (!PowerTunnelService.isRunning) {
Dohp(this).startTunnel()
}
} catch (_: Exception){}
}
//mani
<receiver android:name=".data.model.ProxyStatusEvent"
android:exported="false">
<intent-filter>
<action android:name="com.kotlinx.dohp.broadcast.STARTED" />
</intent-filter>
</receiver>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment