Push Notification init moved to compatibility

This commit is contained in:
Sylvain Berfini 2012-09-10 14:08:29 +02:00
parent ff67b26934
commit 5bc3937f90
3 changed files with 33 additions and 18 deletions

View file

@ -20,18 +20,14 @@ package org.linphone;
import static android.content.Intent.ACTION_MAIN; import static android.content.Intent.ACTION_MAIN;
import org.linphone.core.Log; import org.linphone.compatibility.Compatibility;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; 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(); mHandler = new Handler();
// Starting the push notification service
if (getResources().getBoolean(R.bool.enable_push_id)) { if (getResources().getBoolean(R.bool.enable_push_id)) {
GCMRegistrar.checkDevice(this); Compatibility.initPushNotificationService(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();
}
} }
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {

View file

@ -1,8 +1,16 @@
package org.linphone.compatibility; package org.linphone.compatibility;
import org.linphone.R;
import org.linphone.core.Log;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.Display; import android.view.Display;
import com.google.android.gcm.GCMRegistrar;
/* /*
ApiEightPlus.java ApiEightPlus.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2012 Belledonne Communications, Grenoble, France
@ -30,4 +38,20 @@ public class ApiEightPlus {
public static int getRotation(Display display) { public static int getRotation(Display display) {
return display.getRotation(); 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();
}
}
} }

View file

@ -195,4 +195,10 @@ public class Compatibility {
return ApiFivePlus.isPreferenceChecked(preference); return ApiFivePlus.isPreferenceChecked(preference);
} }
} }
public static void initPushNotificationService(Context context) {
if (Version.sdkAboveOrEqual(8)) {
ApiEightPlus.initPushNotificationService(context);
}
}
} }