This should fix issue when running on Android < 19
This commit is contained in:
parent
d19ab25cb2
commit
cfd93ee7e3
5 changed files with 52 additions and 6 deletions
|
@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
*/
|
||||
package org.linphone;
|
||||
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
@ -57,9 +58,9 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
//make sure the application will at least wakes up every 10 mn
|
||||
Intent newIntent = new Intent(context, KeepAliveReceiver.class);
|
||||
PendingIntent keepAlivePendingIntent = PendingIntent.getBroadcast(context, 0, newIntent, PendingIntent.FLAG_ONE_SHOT);
|
||||
((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP
|
||||
, SystemClock.elapsedRealtime() + 600000
|
||||
, keepAlivePendingIntent);
|
||||
|
||||
AlarmManager alarmManager = ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE));
|
||||
Compatibility.scheduleAlarm(alarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 600000, keepAlivePendingIntent);
|
||||
}
|
||||
} else if (action.equalsIgnoreCase(Intent.ACTION_SCREEN_ON)) {
|
||||
Log.i("[KeepAlive] Screen is on, enable");
|
||||
|
|
|
@ -288,9 +288,8 @@ public final class LinphoneService extends Service {
|
|||
//make sure the application will at least wakes up every 10 mn
|
||||
Intent intent = new Intent(this, KeepAliveReceiver.class);
|
||||
PendingIntent keepAlivePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP
|
||||
, SystemClock.elapsedRealtime() + 600000
|
||||
, keepAlivePendingIntent);
|
||||
AlarmManager alarmManager = ((AlarmManager) this.getSystemService(Context.ALARM_SERVICE));
|
||||
Compatibility.scheduleAlarm(alarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 600000, keepAlivePendingIntent);
|
||||
|
||||
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import org.linphone.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ContentUris;
|
||||
|
@ -168,4 +169,8 @@ public class ApiElevenPlus {
|
|||
public static void setTextAppearance(TextView textview, Context context, int style) {
|
||||
textview.setTextAppearance(context, style);
|
||||
}
|
||||
|
||||
public static void scheduleAlarm(AlarmManager alarmManager, int type, long triggerAtMillis, PendingIntent operation) {
|
||||
alarmManager.set(type, triggerAtMillis, operation);
|
||||
}
|
||||
}
|
||||
|
|
32
src/org/linphone/compatibility/ApiNineteenPlus.java
Normal file
32
src/org/linphone/compatibility/ApiNineteenPlus.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
|
||||
/*ApiNineteenPlus.java
|
||||
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
@TargetApi(19)
|
||||
public class ApiNineteenPlus {
|
||||
public static void scheduleAlarm(AlarmManager alarmManager, int type, long triggerAtMillis, PendingIntent operation) {
|
||||
alarmManager.setExact(type, triggerAtMillis, operation);
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
*/
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
|
@ -129,4 +130,12 @@ public class Compatibility {
|
|||
ApiElevenPlus.setTextAppearance(textview, context, style);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleAlarm(AlarmManager alarmManager, int type, long triggerAtMillis, PendingIntent operation) {
|
||||
if (Version.sdkAboveOrEqual(Version.API19_KITKAT_44)) {
|
||||
ApiNineteenPlus.scheduleAlarm(alarmManager, type, triggerAtMillis, operation);
|
||||
} else {
|
||||
ApiElevenPlus.scheduleAlarm(alarmManager, type, triggerAtMillis, operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue