Android Question Third Party Sdk/ Inline Java - bindService() returns false

Katja

Member
Licensed User
Hello,

I´m trying to integrate an external sdk into a B4A-Application that allows a login by Identity Card via NFC. The sdk´s documentation (Table of contents — AusweisApp2 SDK 1.22.1 documentation (bund.de)) provides some snippets in Java to implement its features. I´m not very familiar with Java but I managed to establish a connection and pass/ receive commands in Android Studio. But with B4A I got stucked: BindService() returns false and onServiceConnection is never called .

This is the Inline Java:

Java:
import com.governikus.ausweisapp2.IAusweisApp2Sdk;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

IAusweisApp2Sdk mSdk;
boolean bound = false;

    public void init() {

        Intent serviceIntent = new Intent("com.governikus.ausweisapp2.START_SERVICE");
        serviceIntent.setPackage("b4a.example");
        getApplicationContext().bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);            
           }
    
    public boolean isBound() {
        return bound;
        }
    

    ServiceConnection mServiceConnection = new ServiceConnection() {
    
       @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
               
           
           
             mSdk = IAusweisApp2Sdk.Stub.asInterface(service);
             bound = true;
         
         
          
        }
        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mSdk = null;
            bound = false;
            }
            
        };

in B4A:

B4X:
Dim jo As JavaObject
    jo.InitializeContext
    jo.RunMethod("init", Null)
    Log(jo.RunMethod("isBound", Null))


What am I doing wrong? I declared the service in the manifest like this:

<service android:name="com.governikus.ausweisapp2.AusweisApp2Service" android:enabled="true"/>


Hopefully somebody here can point me to the right direction. Thanks :)
 

Katja

Member
Licensed User
B4X:
serviceBound = getApplicationContext().bindService(serviceIntent,mServiceConnection, Context.BIND_AUTO_CREATE);    
BA.Log(String.valueOf(serviceBound));

returns false

B4X:
    ServiceConnection mServiceConnection = new ServiceConnection() {
    
       @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {                      
             mSdk = IAusweisApp2Sdk.Stub.asInterface(service);
             bound = true;
             BA.Log("onServiceConnected_Raised");                  
        }

No Log, not raised
 
Upvote 0

Katja

Member
Licensed User
Hi Erel,
you assumed an issue in the manifest, so I checked it again myself before uploading to avoid waisting other people´s time. Just added everything that could be related in some way. It turns out, that the intent must be set in manifest too, like this:
B4X:
<intent-filter>
                <action android:name="com.governikus.ausweisapp2.START_SERVICE"/>
           </intent-filter>
Seems now very simple to me. Maybe I didnt think about that because its not needed to be declared in manifest in my AS project. Anyway, thank you for your time and help with that:)

Regards
 
Upvote 0
Top