Follow

Notification destination reached example

Description

This sample demonstrates how to catch the event "destination reached" from navigation.
They key point here is to catch the flow within the API callback function OnEvent. Within the function we detect the event and if occurring we show a message popup using the Toast function.

Java

import com.sygic.sdk.remoteapi.Api;
import com.sygic.sdk.remoteapi.ApiCallback;
import com.sygic.sdk.remoteapi.events.ApiEvents;
import android.widget.Toast;
...
private Map<Integer,String> mEvents = new HashMap<Integer, String>();
private Api mApi;
private Handler mHandler = new Handler();
private ApiCallback mApiCallback = new ApiCallback() {

		@Override
		public void onServiceDisconnected() {
		}

		@Override
		public void onServiceConnected() {
			try {
				mApi.registerCallback();
			} catch (RemoteException e) {
				Log.e("RegisterCallback", "Error code:" + e.getMessage());
			}
		}

		@Override
        public void onEvent(final int event, final String data)
        {
            boolean show = false;
            switch (event) {
              case ApiEvents.EVENT_ROUTE_FINISH:
                  show = true;
                  break;
            }
            if (show)
            mHandler.post(new Runnable() {
               @Override
               public void run() {
                  String strToast = mEvents.get(event);
                  Toast.makeText(getApplicationContext(), strToast, Toast.LENGTH_SHORT).show();
               }
             });
        }
	};

@Override
protected void onCreate(Bundle savedInstanceState)
{
    ...
    mApi = Api.init(getApplicationContext(),  "com.sygic.drive", "com.sygic.drive.SygicService", mApiCallback);
    mApi.connect();
    mEvents.put(ApiEvents.EVENT_ROUTE_FINISH, "Destination reached");
    ...
}
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments