I developed an app that needs to call the tomtom services at a specific time. For earlier version of the Android 6 I have instantiated an alert and performed the work when it enters BroadcastReceiver. From version 6 onwards google rejects my app because I can not use the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS and consequently my alarm does not work because it is closed by the system.
I read Google Cloud Messaging (GCM), but do not think in my case
there is a solution to my problem?
i want call an specific tom tom service at a specific time.
thanks
My code to setAlarm:
if (Build.VERSION.SDK_INT>=19 && Build.VERSION.SDK_INT<=22) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender);
Log.d(LOG_TAG,"SETTATO ALLARME PER API MAGGIORE DI 19 O MINORE UGUALE A 22");
} else if(Build.VERSION.SDK_INT>22){
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender);
// alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmDate.getTimeInMillis(), sender), sender);
Log.d(LOG_TAG,"SETTATO ALLARME PER API MAGGIORE O UGUALE A 23");
}else {
Log.d(LOG_TAG,"SETTATO ALLARME CON VERSIONE API INFERIORE A 19");
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmDate.getTimeInMillis(), sender);
}
my code to call service:
String result=readUrl("https://api.tomtom.com/lbs/services/route/3/.........");
private static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
StringBuffer buffer = new StringBuffer();
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
int read;
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1)
buffer.append(chars, 0, read);
return buffer.toString();
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, "ERRORE:"+e.getMessage());
}finally {
if (reader != null)
reader.close();
}
return buffer.toString();
}