As B4A don't have yet a lib to the SMS Retriever API (recommend by Google as alternative method)
Based on the post a tried to build an SMS Retriever.
Basically it works. But when the SMS comes in and the Google Api captures it and the send the Broadcast. I get it with a small wrapper, a bit of Manifestcode and some inline java in the starterservice.
B4X:
#if Java
import com.google.android.gms.auth.api.phone.SmsRetriever;
import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.common.api.Status;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public static class MySMSRetriever extends anywheresoftware.b4a.objects.MySMSBCR {
@Override
public void onReceive(Context context, Intent intent) {
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
BA.Log("SMS_RETRIEVED_ACTION retrieved (starter). Get Bundle from Intent...");
Bundle extras = intent.getExtras();
BA.Log("Got Bundle from Intent... Get Status");
Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
BA.Log("(starter)StatusCode="+status.getStatusCode());
BA.Log("(starter)StatusMessage="+status.getStatusMessage());
switch (status.getStatusCode()) {
case CommonStatusCodes.SUCCESS:
// Get SMS message contents
String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
BA.Log("(starter)SMSMessage="+message);
//Intent bcintent = new Intent();
//bcintent.setAction("anywheresoftware.b4a.SMSTokenReceived");
//bcintent.putExtra("data",message);
//bcintent.setClassName("b4a.example.smsverify", "SMSBroadcast");
//BA.Log("(starter)SendBroadcast");
//BA.applicationContext.sendBroadcast(bcintent);
// Extract one-time code from the message and complete verification
// by sending the code back to your server for SMS authenticity.
break;
case CommonStatusCodes.TIMEOUT:
// Waiting for SMS timed out (5 minutes)
// Handle the error ...
BA.Log("Waiting for SMS timed out (5 minutes)");
break;
}
}
}
}
#End If
I cant find the correct way from this inline code to call a Sub in the starter Service with the "message".
Any help would be highly appreciated ;-)
I