Java Question How to start a sub in starter (or activity) from inline java?

DonManfred

Expert
Licensed User
Longtime User
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
The LOGs all do work fine. So till here everything is working as expected. But i need to inform the starter service or any Activity about the result.

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
 

DonManfred

Expert
Licensed User
Longtime User
Can't you raise an event in the inline code?
This was discussed here
from b4a a method in java is called. "BA ba" is part of the call when it arrives in inline java. You Call Method(text)
In inlinejava Method(BA ba, text As String) is called (but BA ba is not visible).
from this ba object i can raise an Event easily.

In my case i did not started a sub to get the right ba Object in the inline java so i can not just use it as it is not defined here.
I´m sure the answer would be easy; i´m not able to get as of now though.
Must be something obvious i guess...
 
Top