Skip to content

Instantly share code, notes, and snippets.

View kishan-vadoliya's full-sized avatar

Kishan Vadoliya kishan-vadoliya

View GitHub Profile
@kishan-vadoliya
kishan-vadoliya / ExactAlarmSetting.kt
Created December 30, 2023 13:44
Set Exact Alarm in Android 13 and above
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT" />
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE" />
<uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />
val receiver = ComponentName(context, AlarmReceiver::class.java)
context.packageManager.setComponentEnabledSetting(
receiver,
@kishan-vadoliya
kishan-vadoliya / Funciones.kt
Last active December 26, 2023 13:31
Inline function kotlin
import java.util.stream.IntStream
object Funciones {
private const val NUMERO_MULTIPLO_DE_PAR = 2
private infix fun Int.doubleDiv(i: Int): Double = this / i.toDouble()
infix fun Int.esMultiplo(numero:Int):Boolean = this % numero == 0
@kishan-vadoliya
kishan-vadoliya / SwiftUI_Ad_Banner.swift
Created December 26, 2023 10:15
A google AdMob Banner implementation in SwiftUI
import SwiftUI
import GoogleMobileAds
import UIKit
final private class BannerVC: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let view = GADBannerView(adSize: kGADAdSizeBanner)
let viewController = UIViewController()
view.adUnitID = bannerID
view.rootViewController = viewController
viewController.view.addSubview(view)
@kishan-vadoliya
kishan-vadoliya / MyApplication.kt
Created December 25, 2023 11:52
OneSignalSetup
OneSignalUtils.setupOneSignal(instance.applicationContext)
// Resource Required
1. small icon
2. large icon
@kishan-vadoliya
kishan-vadoliya / AndroidManifests.kt
Created December 20, 2023 05:05
Reminder Module
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <!-- Notification Permission -->
<application ...>
<receiver
android:name=".notifyme.NotificationPublisher"
android:enabled="true"
android:exported="true"
@kishan-vadoliya
kishan-vadoliya / InlineClasses.kt
Created October 20, 2023 12:10
Inline classes in Kotlin?
// Why use inline classes? 🤔
// 🎯 Compile time safety
// 🎯 Less runtime overhead than a normal wrapper class as it "inlines" the data into its usages
// More info : https://kotlinlang.org/docs/reference/inline-classes.html
// Without inline classes 😞
data class Recipe(id: UUID)
data class Ingredient(id: UUID, recipeId: UUID)
@kishan-vadoliya
kishan-vadoliya / BannerAds.kt
Created October 20, 2023 09:36
Android’s Jetpack Compose and Admob ads
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MobileAds.initialize(this) {}
setContent {
JetpackAdmobDemoTheme {
// A surface container using the 'background' color from the theme
Column(
Modifier
.fillMaxSize()
.background(color = Color.LightGray),
@kishan-vadoliya
kishan-vadoliya / BouncyRopes.kt
Created October 20, 2023 09:25
Jetpack Compose Bouncy Ropes
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun BouncyRopes() {
val startCoOrdinate by remember {
mutableStateOf(Offset(0f, 0f))
}
var endCoOrdinate by remember {
mutableStateOf(Offset(100f, 0f))
}
@kishan-vadoliya
kishan-vadoliya / InstallReferrerExt.kt
Created October 20, 2023 09:04
Install Referrer KTX - Kotlin Coroutine friendly wrapper for the Google Play's InstallReferrerClient API. This API is used to ask Google Play about where the installation originated.
import android.content.Context
import android.os.RemoteException
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.android.installreferrer.api.ReferrerDetails
import kotlinx.coroutines.CompletableDeferred
/**
* https://developer.android.com/google/play/installreferrer/library
*
@kishan-vadoliya
kishan-vadoliya / ComposeOverlayViewService.kt
Created October 20, 2023 09:04
Jetpack Compose OverlayService. Service ready to display complete view (with the right context to access the window manager and layout inflater if needed, but also access to a saved state registry and a view model store owner). Then a compose overlay service, that use the first one to push a compose view as system overlay, and also proposing a s…
import android.content.Intent
import android.graphics.PixelFormat
import android.os.IBinder
import android.view.Gravity
import android.view.WindowManager
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue