Beispiel #1
0
    @Override
    public void onEnter(Place place, long time) {
      //			Activity activity = BackgroundGeofencingPlugin.this.cordova.getActivity();
      NotificationManager mNotificationManager =
          (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
      JSONObject offerData = new JSONObject();
      try {
        offerData.put("offerUuid", place.getOfferUuid());
        offerData.put("placeName", place.getPlaceName());
      } catch (JSONException e) {
        e.printStackTrace();
      }

      Intent intent = new Intent(activity, CordovaApp.class);
      //			intent.addCategory(INTENT_CATEGORY_OFFER_NOTIFICATION);
      Uri.Builder uriBuilder = new Uri.Builder();
      uriBuilder.scheme(INTENT_DATA_SCHEME_OFFER_NOTIFICATION);
      uriBuilder.authority(INTENT_HOST_OFFER_NOTIFICATION);
      uriBuilder.appendQueryParameter("placeUuid", place.getUuid());
      intent.setData(uriBuilder.build());
      intent.putExtra(INTENT_EXTRA_KEY_NOTIFICATION_OFFER_DATA, offerData.toString());
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      PendingIntent pendingIntent =
          PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

      Notification.Builder builder = new Notification.Builder(activity);
      // builder.setContentTitle(place.getPlaceName()+" has a new offer"); //By Abdullah
      builder.setContentTitle(place.getPlaceName()); // By Abdullah
      // builder.setContentText("Click here to view the offer");		//By Abdullah
      builder.setContentText(place.getShortDesc()); // By Abdullah
      builder.setSmallIcon(R.drawable.icon);
      builder.setContentIntent(pendingIntent);
      builder.setAutoCancel(true);
      builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

      mNotificationManager.notify((int) System.currentTimeMillis(), builder.build());

      Log.v(Config.TAG, "enter into place :" + place.getPlaceName() + "	at time:" + time);

      // unregister place in apigee
      Intent tripPlanSyncIntent = new Intent(activity, TripPlanSyncService.class);
      tripPlanSyncIntent.putExtra(TripPlanSyncService.PLACE_ID_TO_UNSUBSRIBE, place.getUuid());
      activity.startService(tripPlanSyncIntent);
    }