Skip to content

Instantly share code, notes, and snippets.

val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val workRequest = ExpeditedWorkRequestBuilder<MyExpeditedWorker>()
.setConstraints(constraints)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
val workRequest = ExpeditedWorkRequestBuilder<MyExpeditedWorker>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
WorkManager.getInstance(context).enqueue(workRequest)
class AppApplicationClass : Application() {
override fun onCreate() {
super.onCreate()
initNotifs()
}
private fun initNotifs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(getSilentChannel())
fun createNotification(): Notification {
val channelID = "Silent_Channel"
val notificationTitle = "My Work Notification"
return NotificationCompat.Builder(applicationContext, channelID)
.setContentTitle(notificationTitle)
.setSmallIcon(R.drawable.ic_notification_icon_new)
.setProgress(0, 0, true)
.setColor(ContextCompat.getColor(applicationContext, R.color.color_primary))
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
class MyExpeditedWorker(
context: Context,
params: WorkerParameters,
) : CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
// Your task code here
return Result.success()
}
class MyService : Service() {
private val serviceBroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.i("onReceive", "$intent Extras - ${intent.extras.toString()}")
}
}
override fun onCreate() {
super.onCreate()
val intent = Intent("NOTHING_TO_SEE_HERE_BROADCAST")
intent.putExtra("data", "some data you want to send")
sendBroadcast(intent)
@faanghutProfile
faanghutProfile / RunningSum.py
Created January 22, 2023 19:35
Solution to LeetCode Problem - Running Sum of 1D Array
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
if (len(nums) >= 1):
for i in range(1, len(nums)):
nums[i] += nums[i-1]
return nums
@faanghutProfile
faanghutProfile / checkDeveloperSettings.kt
Created December 19, 2022 16:43
Function to check if developer settings is enabled
fun isDeveloperOptionsEnabled(context: Context): Boolean {
return when {
Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN -> {
Settings.Secure.getInt(context.contentResolver,
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN -> {
Settings.Secure.getInt(context.contentResolver,
Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hmap = dict()
for i in range(len(nums)):
if target - nums[i] in hmap:
return (i, hmap[target - nums[i]])
hmap[nums[i]] = i
return null