diff --git a/src/org/linphone/LinphoneLauncherActivity.java b/src/org/linphone/LinphoneLauncherActivity.java index 128f0334a..b575d1b0d 100644 --- a/src/org/linphone/LinphoneLauncherActivity.java +++ b/src/org/linphone/LinphoneLauncherActivity.java @@ -20,18 +20,14 @@ package org.linphone; import static android.content.Intent.ACTION_MAIN; -import org.linphone.core.Log; +import org.linphone.compatibility.Compatibility; import org.linphone.mediastream.Version; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; - -import com.google.android.gcm.GCMRegistrar; /** * @@ -59,20 +55,9 @@ public class LinphoneLauncherActivity extends Activity { mHandler = new Handler(); - // Starting the push notification service + if (getResources().getBoolean(R.bool.enable_push_id)) { - GCMRegistrar.checkDevice(this); - GCMRegistrar.checkManifest(this); - final String regId = GCMRegistrar.getRegistrationId(this); - if (regId.equals("")) { - GCMRegistrar.register(this, getString(R.string.push_sender_id)); - } else { - Log.e("Push Notification : already registered with id = " + regId); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(this.getString(R.string.push_reg_id_key), regId); - editor.commit(); - } + Compatibility.initPushNotificationService(this); } if (LinphoneService.isReady()) { diff --git a/src/org/linphone/compatibility/ApiEightPlus.java b/src/org/linphone/compatibility/ApiEightPlus.java index b5c5df28b..08252ea1e 100644 --- a/src/org/linphone/compatibility/ApiEightPlus.java +++ b/src/org/linphone/compatibility/ApiEightPlus.java @@ -1,8 +1,16 @@ package org.linphone.compatibility; +import org.linphone.R; +import org.linphone.core.Log; + import android.annotation.TargetApi; +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.view.Display; +import com.google.android.gcm.GCMRegistrar; + /* ApiEightPlus.java Copyright (C) 2012 Belledonne Communications, Grenoble, France @@ -30,4 +38,20 @@ public class ApiEightPlus { public static int getRotation(Display display) { return display.getRotation(); } + + public static void initPushNotificationService(Context context) { + // Starting the push notification service + GCMRegistrar.checkDevice(context); + GCMRegistrar.checkManifest(context); + final String regId = GCMRegistrar.getRegistrationId(context); + if (regId.equals("")) { + GCMRegistrar.register(context, context.getString(R.string.push_sender_id)); + } else { + Log.e("Push Notification : already registered with id = " + regId); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(context.getString(R.string.push_reg_id_key), regId); + editor.commit(); + } + } } diff --git a/src/org/linphone/compatibility/Compatibility.java b/src/org/linphone/compatibility/Compatibility.java index 3d884a56f..7a03421d1 100644 --- a/src/org/linphone/compatibility/Compatibility.java +++ b/src/org/linphone/compatibility/Compatibility.java @@ -195,4 +195,10 @@ public class Compatibility { return ApiFivePlus.isPreferenceChecked(preference); } } + + public static void initPushNotificationService(Context context) { + if (Version.sdkAboveOrEqual(8)) { + ApiEightPlus.initPushNotificationService(context); + } + } }