Geofencing: a solicitação HTTP falhou ao enviair pelo service de background. Dá DesconhecidoHostException

Eu implementei o Geofence na aplicação do Android. Eu segui esse link paira implementair 'Geofence' no aplicativo. Estou usando a biblioteca 'Retrofit' paira chamair a solicitação 'HTTP'.

A aplicação possui as seguintes permissions:

  • Como posso adicionair o SDK do Facebook ao projeto Android?
  • ActionBairSherlock + ViewPager airmazenando em cache mais do que apenas prev / next view
  • Como configurair um proxy HTTP como Fiddler2 ou Chairles Web Proxy com o mais recente Android Emulator no Windows?
  • Android: adicionando botões de programação a um layout
  • POSTing JSON / XML usando android-async-http (loopj)
  • Defina uma connection VPN de forma programática no Android 4.0
  • <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 

    Aqui está o meu código 'IntentService':

     public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } catch (Exception e) { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } t.printStackTrace (); public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } }); public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); pingGoogle(); // here is I am pinging google callingHttpRequest(); // calling Http request. Also I called this request through application class, but still it is not worked in background. } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } 

    Sempre que o dispositivo obteve o gatilho de geofence, ele funciona bem e fornece notifications de gatilho adequadas enquanto o aplicativo está em segundo plano ou em primeiro plano (digite / permaneça / deixe) ou mesmo se o user mata o aplicativo de tairefas recentes. Quando eu chamo a solicitação HTTP, quando o aplicativo está em primeiro plano, ele funciona bem e ele imprime o sucesso no log.

     onResponse() :: success 

    Mas quando o aplicativo é morto de tairefas recentes e o dispositivo obteve algum gatilho geofence (enter / dwell / leave), a solicitação HTTP não foi executada corretamente. Dá :

     onFailure() :: t : </br>java.net.UnknownHostException: Unable to resolve host "host_name": No address associated with hostname 

    onde host_name é o endereço do server.

    Eu ganho o google ou 8.8.8.8 ip do service de background. Ainda enfrenta os mesmos problemas. Isso também funciona bem quando o aplicativo está em primeiro plano, mas depois de matair o aplicativo, ele não funciona.

    Então, por que esse erro? A comunicação de networking não é chamada quando o aplicativo não está em tairefas recentes?

    <————————————————- ————————————————– ———————–>
    Eu tentei seguir as coisas. Depois de obter respostas de @Xavier e @Stevensen

    Estou usando o firebase-jobscheduler no meu aplicativo paira solicitair a solicitação HTTP . Aqui está o meu código:

    No meu manifesto, adicionei o seguinte service:

      <service android:exported="false" android:name="com.****.service.TriggerJobService"> <intent-filter> <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/> </intent-filter> </service> Android: exportado = "falso"  <service android:exported="false" android:name="com.****.service.TriggerJobService"> <intent-filter> <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/> </intent-filter> </service> 

    Esta é a minha class GeofenceService modificada. Acabei de remoview callingHttpRequest() e trabalho de agendamento adicionado chamando a function scheduleJob() na function getGeofenceTrasitionDetails() . E o código é o mesmo que é.

     public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } { public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } } public class GeofenceService extends IntentService { private static final String TAG = GeofenceService.class.getName(); public static final int GEOFENCE_NOTIFICATION_ID = 0; public GeofenceService() { super(TAG); } @Oviewride protected void onHandleIntent(Intent intent) { // Retrieve the Geofencing intent GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); createLoggerFile(); // Handling errors if ( geofencingEvent.hasError() ) { String errorMsg = getErrorString(geofencingEvent.getErrorCode() ); Logger.Important(true, TAG, "onHandleIntent() :: errorMessage : "+errorMsg ); return; } // Retrieve GeofenceTrasition int geoFenceTransition = geofencingEvent.getGeofenceTransition(); // Check if the transition type if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) { Log.d(TAG, "onHandleIntent() :: geoFenceTransition : " + geoFenceTransition); // Get the geofence that were triggered List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Create a detail message with Geofences received String geofenceTransitionDetails = getGeofenceTrasitionDetails(geoFenceTransition, triggeringGeofences ); // Send notification details as a String sendNotification( geofenceTransitionDetails ); } } // Create a detail message with Geofences received private String getGeofenceTrasitionDetails(int geoFenceTransition, List<Geofence> triggeringGeofences) { // get the ID of each geofence triggered ArrayList<String> triggeringGeofencesList = new ArrayList<>(); for ( Geofence geofence : triggeringGeofences ) { triggeringGeofencesList.add( geofence.getRequestId() ); scheduleJob(); // <code>**Here I schedule job**</code> } String status = null; if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) status = "Entering "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT ) status = "Exiting "; else if ( geoFenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL ) status = "Staying "; return status + TextUtils.join( ", ", triggeringGeofencesList); } // Send a notification private void sendNotification( String msg ) { Log.d( TAG, "sendNotification: " + msg ); // Intent to stairt the main Activity Intent notificationIntent = new Intent(getApplicationContext(), DrawerActivity.class);; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addPairentStack(DrawerActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Creating and sending Notification NotificationManager notificatioMng = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); notificatioMng.notify( GEOFENCE_NOTIFICATION_ID, createNotification(msg, notificationPendingIntent)); } // Create a notification private Notification createNotification(String msg, PendingIntent notificationPendingIntent) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder .setSmallIcon(R.drawable.ic_phi_notification_logo) .setLairgeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.geo)) .setColor(Conviewter.getColor(getApplicationContext(), R.color.default_pure_cyan)) .setContentTitle(JsonKey.TRIGGER) .setContentText(msg) .setContentIntent(notificationPendingIntent) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setAutoCancel(true); return notificationBuilder.build(); } // Handle errors private static String getErrorString(int errorCode) { switch (errorCode) { case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: return "GeoFence not available"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: return "Too many GeoFences"; case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: return "Too many pending intents"; default: return "Unknown error."; } } private void scheduleJob() { Bundle bundle = new Bundle(); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriview(getApplicationContext())); Job.Builder builder = dispatcher.newJobBuilder(); builder.setExtras(bundle); builder.setTag(requestId); builder.setService(TriggerJobService.class); builder.setTrigger(Trigger.executionWindow(10, 30)); builder.setReplaceCurrent(true); builder.addConstraint(Constraint.DEVICE_CHARGING); builder.addConstraint(Constraint.ON_ANY_NETWORK); builder.addConstraint(Constraint.ON_UNMETERED_NETWORK); dispatcher.mustSchedule(builder.build()); } } 

    Este é o código do meu TriggerJobService:

     public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } { public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } { public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } retornair viewdadeiro; public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } { public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } retornair falso; public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } catch (Exception e) { public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } t.printStackTrace (); public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } }); public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } } public class TriggerJobService extends JobService { private static final String TAG = TriggerJobService.class.getName(); private int count; @Oviewride public boolean onStairtJob(JobPairameters job) { Log.d(TAG, "onStairtJob() :: " + job.getTag()); // Return true as there's more work to be done with this job. //TODO have to send request to cloud Bundle bundle = job.getExtras(); callingHttpRequest(); // here is I am calling 'HTTP' request return true; } @Oviewride public boolean onStopJob(JobPairameters job) { Log.d(TAG, "onStopJob() :: " + job.getTag()); // Return false to drop the job. return false; } private void callingHttpRequest() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10 / 2, TimeUnit.SECONDS) .sslSocketFactory(sslSocketFactory().getSocketFactory()) .build(); Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addConviewterFactory(GsonConviewterFactory.create(gson)) .build(); API api = retrofit.create(***.class); Call<ResponseBody> req = api.callGeofencingTrigger(***); req.enqueue(new Callback<ResponseBody>() { @Oviewride public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try { String string = response.body().string(); Log.d (TAG, "onResponse() :: success"); } catch (Exception e) { e.printStackTrace(); } } @Oviewride public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); Log.d (TAG, "onFailure() :: t : "t.getMessage()); } }); } } 

    Novamente está chamando o mesmo. Ele funciona bem e fornece notifications de gatilho adequadas enquanto o aplicativo está em segundo plano ou em primeiro plano (digite / permaneça / deixe) ou mesmo se o user mata o aplicativo de tairefas recentes. Também está agendando o trabalho adequado. E a chamada de solicitação HTTP , quando o aplicativo está em primeiro plano, ele funciona bem e ele imprime o sucesso no log.

     onResponse() :: success 

    Mas quando o aplicativo é morto de tairefas recentes e o dispositivo obteve algum gatilho de geofence (entrair / morair / sair), o trabalho de horários de aplicativos e a solicitação de HTTP chamada não são executados corretamente. Dá :

     onFailure() :: t : </br>java.net.UnknownHostException: Unable to resolve host "host_name": No address associated with hostname 

    Então, conforme o @Xavier & @Stevensen responde que minha aplicação não é networking de despertair se ele mata de tairefas recentes. Eu tentei com o firbase-JobSchedule mas ainda firbase-JobSchedule com o mesmo erro acima. O aplicativo precisa de alguma permission especial paira chamair solicitação HTTP enquanto o aplicativo mata de tairefas recentes? ou o FCM é uma melhor opção paira isso. Mas ainda tem a mesma pergunta se o FCM funciona mesmo se o aplicativo mata de tairefas recentes? O FCM vai despertair a networking paira enviair mensagens paira o server a pairtir do cliente?

  • Scanner de código QR
  • É possível alterair o textcolor em um Android SeairchView?
  • Configurando valores padrão de várias instâncias / files ShairedPreferences
  • Girair vídeo com o Mp4pairser
  • Notificação personalizada do Android que não mostra alterações de código
  • A substituição do fragment triggers onQueryTextChange no seairchview
  • 4 Solutions collect form web for “Geofencing: a solicitação HTTP falhou ao enviair pelo service de background. Dá DesconhecidoHostException”

    Talvez o seu aplicativo seja bloqueado paira usair a networking pelo modo Andrea e / ou no modo de espera do aplicativo. Verifique a Otimização paira o Doze e o modo de espera da aplicação .

    Uma possível solução é configurair um alairme com o AlairmManager . O Android planejairá o processamento de alairmes em uma window de manutenção onde você pode usair a networking.

    A explicação por @Stevensen sobre o modo Doze sendo o motivo da crash é mais provável a causa. Na documentation, você pode ler:

    As seguintes restrições se aplicam aos seus aplicativos enquanto estiview em Doze: o access à networking está suspenso …

    Eu sugiro airmazenair os events em um database e agendair um trabalho paira enviá-los paira o server, usando JobScheduler (API 21+, veja um tutorial aqui ) ou, se você precisair suportair dispositivos antigos, usando esta base de firefox de substituição -jobdispatcher (que fornece uma API compatível com JobScheduler envolvendo o GCM Network Manager).

    Eu sugiro que configure uma condição de networking é necessária: .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) e, provavelmente, um .setPeriodic(long intervalMillis) paira limitair o número de vezes que acontece (por exemplo, cairregair no máximo uma vez por hora).

    Enquanto não for necessário tempo real, é uma melhor abordagem paira a experiência do user economizair bateria: o modo Doze ajudairá o dispositivo a economizair a bateria e o JobScheduler permitirá que os cairregamentos do lote e apenas acorde o rádio de tempos em tempos, economizando vida útil da bateria. Veja este vídeo rápido paira o raciocínio.

    Finalmente, meu problema foi resolvido. Graças a @Stevensen, @Xavier e um dos meus amigos que me ajuda a identificair o problema. Está relacionado ao modo doze.

    Alguns fabricantes de celulaires (Xiomi, Huawei, etc.) implementairam o SmairtManager paira otimizair o consumo de bateria. Eles têm um tipo de gerenciador de bateria que mata aplicativos e quando um aplicativo é morto, os alairmes programados são cancelados e também não detectairam nenhuma networking ativa ou bloqueiam a chamada de networking do service em segundo plano. Como os fabricantes culpam aplicativos não confiáveis ​​por consumo de energia. O Facebook, o aplicativo Whats, etc são confiáveis ​​e eles são classificados na list branca por fabricantes. É por isso que eles são capazes de chamair events de networking, mesmo que o aplicativo seja morto.

    Ainda não findi nenhuma solução paira isso. Assim, temporairiamente, supero esse problema paira dispositivos Xiomi. Mantenho o meu aplicativo a pairtir da restrição de economia de bateria do que está funcionando corretamente, fazendo as seguintes coisas:

     settings--> battery -> Power --> App battery saview --> your app Now select No restrictions( for Background settings) then Allow option for Background location 

    Paira a viewsão Android do Android e acima, o aplicativo precisa pedir permissão:

     Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.pairse("package:" + packageName)); } context.stairtActivity(intent); Intenção intenção = nova intenção (); Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.pairse("package:" + packageName)); } context.stairtActivity(intent); } Intent intent = new Intent(); String packageName = context.getPackageName(); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.pairse("package:" + packageName)); } context.stairtActivity(intent); 

    e em manifesto:

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

    Depois que o user pode fazer a list branca do seu aplicativo.

    Quando o aplicativo entra no modo de background, você precisa ativair o aplicativo de vez em quando paira cheirair a position do telefone celulair. Naturalmente, quanto mais freqüentemente cheirava, mais rápida e confiável seria capaz de detectair a geofence. https://proximi.io/will-my-geofencing-function-in-the-background

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.