This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val constraints = Constraints.Builder() | |
| .setRequiredNetworkType(NetworkType.CONNECTED) | |
| .build() | |
| val workRequest = ExpeditedWorkRequestBuilder<MyExpeditedWorker>() | |
| .setConstraints(constraints) | |
| .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val workRequest = ExpeditedWorkRequestBuilder<MyExpeditedWorker>() | |
| .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) | |
| .build() | |
| WorkManager.getInstance(context).enqueue(workRequest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyExpeditedWorker( | |
| context: Context, | |
| params: WorkerParameters, | |
| ) : CoroutineWorker(context, params) { | |
| override suspend fun doWork(): Result { | |
| // Your task code here | |
| return Result.success() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val intent = Intent("NOTHING_TO_SEE_HERE_BROADCAST") | |
| intent.putExtra("data", "some data you want to send") | |
| sendBroadcast(intent) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
NewerOlder