Poynt Services Crash

Hi,

I’m trying to use IPoyntBusinessService, but I’m getting a NPE on Poynt Services when binding it. Running on emulator.

Gradle:

// Poynt
compile 'co.poynt.api:android-api-model:1.2.32@jar'
compile 'co.poynt.android.sdk:poynt-sdk:1.2.8@aar'

(getting the same with SDK 1.2.10 & Model 1.2.36 or SDK 1.2.11 & Model 1.2.44)

Permissions:

<uses-permission android:name="poynt.permission.BUSINESS_SERVICE" />

Usage:

public class LoginActivity extends AppCompatActivity {

  private IPoyntBusinessService iPoyntBusinessService;

  private ServiceConnection iPoyntBusinessServiceConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
      iPoyntBusinessService = IPoyntBusinessService.Stub.asInterface(service);
      onBusinessServiceStateChange(iPoyntBusinessService);
    }

    public void onServiceDisconnected(ComponentName className) {
      iPoyntBusinessService = null;
    }
  };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // ...

      Intent intent = new Intent(IPoyntBusinessService.class.getName());
      bindService(intent, iPoyntBusinessServiceConnection, BIND_AUTO_CREATE);
  }

  public void onBusinessServiceStateChange(IPoyntBusinessService iPoyntBusinessService) {
    try {
      iPoyntBusinessService.getBusiness(new IPoyntBusinessReadListener() {
        @Override
        public void onResponse(Business business, PoyntError poyntError) throws RemoteException {
          System.out.println("MID: " + business.getExternalMerchantId());
        }

        @Override
        public IBinder asBinder() {
          return null;
        }
      });
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }
}

Logcat:

04-19 10:07:26.176 9010-9010/co.poynt.services E/AndroidRuntime: FATAL EXCEPTION: main
Process: co.poynt.services, PID: 9010
java.lang.NullPointerException
    at co.poynt.services.tasks.business.LoadBusinessTask.onPostExecute(LoadBusinessTask.java:77)
    at co.poynt.services.tasks.business.LoadBusinessTask.onPostExecute(LoadBusinessTask.java:24)
    at android.os.AsyncTask.finish(AsyncTask.java:632)
    at android.os.AsyncTask.access$600(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)


Adding some more information that I think it’s useful:
Emulator was setup with version v1.2.8. I thought that it was causing some issue, then I saw version 1.2.11 on the Setup PoyntOS Emulator page and created a new virtual device with Genymotion, installed it and now when I open the SetupWizard, Poynt Services stop working with:


04-19 16:35:14.678 4109-4109/co.poynt.services E/AndroidRuntime: FATAL EXCEPTION: main
Process: co.poynt.services, PID: 4109
java.lang.RuntimeException: Unable to create application co.poynt.services.PoyntServicesApplicationImpl: java.lang.SecurityException: Not allowed to bind to service Intent { act=co.poynt.os.services.v1.IPoyntCapabilityManager }
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4331)
   at android.app.ActivityThread.access$1500(ActivityThread.java:135)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5001)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=co.poynt.os.services.v1.IPoyntCapabilityManager }
   at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1596)
   at android.app.ContextImpl.bindService(ContextImpl.java:1560)
   at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
   at co.poynt.os.util.CapabilityProviderServiceHelper.bindCapabilityManager(CapabilityProviderServiceHelper.java:59)
   at co.poynt.os.util.CapabilityProviderServiceHelper.<init>(CapabilityProviderServiceHelper.java:53)
   at co.poynt.services.PoyntServicesApplication.onCreate(PoyntServicesApplication.java:107)
   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
   at android.app.ActivityThread.access$1500(ActivityThread.java:135) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:136) 
   at android.app.ActivityThread.main(ActivityThread.java:5001) 
   at java.lang.reflect.Method.invokeNative(Native Method) 
   at java.lang.reflect.Method.invoke(Method.java:515) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
   at dalvik.system.NativeStart.main(Native Method) 

Thanks in advance. (:

Found my error:

I was using IPoyntBusinessReadListener directly, instead of IPoyntBusinessReadListener.Stub. Rest of the code was alright.