How to launch Google Autofill's "Scan New Card" intent programmatically
Asked Answered
N

0

6

I want to launch the "Scan New Card" activity from my Android Application. This functionality is provided by Google to scan and fill the credit/debit card number inside the EditText and is the part of GMS Autofill Service.

My purpose is to provide a button to launch this intent, instead of using the existing option which shows up in the Autofill Popup/Ime Options.

I need to develop something like these screenshots from Google Play Store's Add Payment method and Google Autofill's Add Payment method.

Google Play Store's Add Payment method Google Autofill's Add Payment method Scan New Card IME option via Autofill
Google Play Store's Add Payment method Google Autofill's Add Payment method Scan New Card IME option via Autofill

What I've tried:

  1. I have tried the conventional way of adding the autofillHint="creditCardNumber" to the EditText and thus showing the option to launch using the autofill service, however, if, for some reason, the Autofill service is disabled or not set to "Google" then this autofill option of "Scan New Card" doesn't show up.

  2. I have tried to launch the intent directly using the Activity and Package name I found from the Logcat, however a Permission Denied: Activity not exported is thrown.

My Findings:

Logcat output when "Scan New Card" option provided by Google Autofill Service is clicked:

START u0 {act=SCAN_PAYMENT_CARD cmp=com.google.android.gms/.autofill.ui.AutofillActivity (has extras)} from uid 10102
START u0 {act=com.google.android.gms.ocr.ACTION_CREDIT_CARD_OCR pkg=com.google.android.gms cmp=com.google.android.gms/.ocr.SecuredCreditCardOcrActivity (has extras)} from uid 10102

Logcat output when launching the above intent directly using the Activity and Package name:

Permission Denial: starting Intent { act=SCAN_PAYMENT_CARD cmp=com.google.android.gms/.autofill.ui.AutofillActivity } from ProcessRecord{a45d996 13710:com.example.activity/u0a88} (pid=13710, uid=10088) not exported from uid 10013
FATAL EXCEPTION: main
Process: com.example.activity, PID: 13710
java.lang.SecurityException: Permission Denial: starting Intent { act=SCAN_PAYMENT_CARD cmp=com.google.android.gms/.autofill.ui.AutofillActivity } from ProcessRecord{a45d996 13710:com.example.activity/u0a88} (pid=13710, uid=10088) not exported from uid 10013

TLDR: I want to launch the following screen directly from a click of a button from my application instead of depending on the Google's Autofill Service.

Scan a Card Activity provided by Google's Autofill Service

Nonbeliever answered 18/2, 2023 at 4:23 Comment(3)
Check this out this can help you for sure. https://mcmap.net/q/700467/-android-credit-card-scan-library-or-any-api-except-card-io-closedDanny
Thanks for the link @SachinHarne, however, most of the libraries mentioned in the answer are not maintained actively or have blocking issues. Relying on Google's service handles the maintenance problem.Nonbeliever
@Nonbeliever did you find anything. I used a test HTML code in a webview which shows up this small dialog 'scan new card' jsfiddle.net/q4gz33dg/2 but no luck with native implementationTopographer

© 2022 - 2024 — McMap. All rights reserved.