Skip to content

Instantly share code, notes, and snippets.

View MehulKK's full-sized avatar
🏠
Working from home

Mehul Kabaria MehulKK

🏠
Working from home
View GitHub Profile
dependencies {
def work_version = "2.2.0"
// (Java only)
implementation "androidx.work:work-runtime:$work_version"
// Kotlin + coroutines
implementation "androidx.work:work-runtime-ktx:$work_version"
// optional - RxJava2 support
public class AppSignatureHelper extends ContextWrapper {
public static final String TAG = AppSignatureHelper.class.getSimpleName();
private static final String HASH_TYPE = "SHA-256";
public static final int NUM_HASHED_BYTES = 9;
public static final int NUM_BASE64_CHAR = 11;
public AppSignatureHelper(Context context) {
super(context);
}
<receiver android:name=".MySMSBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED" />
</intent-filter>
</receiver>
class MySMSBroadcastReceiver : BroadcastReceiver() {
private var otpReceiver: OTPReceiveListener? = null
/**
* @param receiver OTPReceiveListener
*/
fun initOTPListener(receiver: OTPReceiveListener) {
this.otpReceiver = receiver
}
private fun startSMSListener() {
val client = SmsRetriever.getClient(this /* context */)
val task = client.startSmsRetriever()
task.addOnSuccessListener {
// Successfully started retriever, expect broadcast intent
// ...
// otpTxtView.text = "Waiting for the OTP"
Timber.e("SMS Retriever starts")
}
// Obtain the phone number from the result
fun onActivityResult(requestCode:Int, resultCode:Int, data:Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RESOLVE_HINT)
{
if (resultCode == RESULT_OK)
{
val credential = data.getParcelableExtra(Credential.EXTRA_KEY)
// credential.getId(); <-- will need to process phone number string
}
// Construct a request for phone numbers and show the picker
private fun requestHint() {
val hintRequest = HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build()
val intent = Auth.CredentialsApi.getHintPickerIntent(
apiClient, hintRequest)
startIntentSenderForResult(intent.getIntentSender(),
RESOLVE_HINT, null, 0, 0, 0)
}
dependencies {
implementation 'com.google.android.gms:play-services-base:11.6.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:11.6.0'
//Optional for phone number hint
implementation 'com.google.android.gms:play-services-auth:11.6.0'
}
@MehulKK
MehulKK / TextDrawable
Created September 24, 2018 10:56
Create Drawable from Text.
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/firstFragment">
<fragment
android:id="@+id/firstFragment"
android:name="com.mehul.navarchicomponentdemo.FirstFragment"
android:label="FirstFragment">
<action