Use reflection to detect if GCM is available, so it is an optional dependency
This commit is contained in:
parent
a7ad4001c2
commit
0e10ba8a88
1 changed files with 37 additions and 32 deletions
|
@ -1,5 +1,7 @@
|
||||||
package org.linphone.compatibility;
|
package org.linphone.compatibility;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.linphone.LinphonePreferences;
|
import org.linphone.LinphonePreferences;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
@ -8,8 +10,6 @@ import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
|
||||||
import com.google.android.gcm.GCMRegistrar;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ApiEightPlus.java
|
ApiEightPlus.java
|
||||||
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
||||||
|
@ -26,42 +26,47 @@ GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@TargetApi(8)
|
@TargetApi(8)
|
||||||
public class ApiEightPlus {
|
public class ApiEightPlus {
|
||||||
|
|
||||||
public static void initPushNotificationService(Context context) {
|
public static void initPushNotificationService(Context context) {
|
||||||
try {
|
try {
|
||||||
// Starting the push notification service
|
Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
|
||||||
GCMRegistrar.checkDevice(context);
|
// Starting the push notification service
|
||||||
try {
|
GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, context);
|
||||||
GCMRegistrar.checkManifest(context);
|
try {
|
||||||
} catch (IllegalStateException e){
|
GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, context);
|
||||||
Log.e("No receiver found",e);
|
} catch (IllegalStateException e){
|
||||||
}
|
Log.e("Push notification: No receiver found",e);
|
||||||
final String regId = GCMRegistrar.getRegistrationId(context);
|
}
|
||||||
String newPushSenderID = context.getString(R.string.push_sender_id);
|
final String regId = (String)GCMRegistrar.getMethod("getRegistrationId", Context.class).invoke(null, context);
|
||||||
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
|
String newPushSenderID = context.getString(R.string.push_sender_id);
|
||||||
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
|
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
|
||||||
GCMRegistrar.register(context, newPushSenderID);
|
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
|
||||||
|
GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, context, new String[]{newPushSenderID});
|
||||||
|
|
||||||
Log.d("Push Notification : storing current sender id = " + newPushSenderID);
|
Log.d("Push Notification: storing current sender id = " + newPushSenderID);
|
||||||
LinphonePreferences.instance().setPushNotificationRegistrationID(newPushSenderID);
|
LinphonePreferences.instance().setPushNotificationRegistrationID(newPushSenderID);
|
||||||
} else {
|
} else {
|
||||||
Log.d("Push Notification : already registered with id = " + regId);
|
Log.d("Push Notification: already registered with id = " + regId);
|
||||||
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
||||||
}
|
}
|
||||||
} catch (java.lang.UnsupportedOperationException e) {
|
} catch (java.lang.UnsupportedOperationException e) {
|
||||||
Log.i("Push Notification not activated");
|
Log.i("Push Notification: not activated");
|
||||||
}
|
} catch (Exception e1) {
|
||||||
}
|
//assume the jar is not provided
|
||||||
|
Log.i("Push Notification: assuming GCM jar is not provided.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static String getAudioManagerEventForBluetoothConnectionStateChangedEvent() {
|
public static String getAudioManagerEventForBluetoothConnectionStateChangedEvent() {
|
||||||
return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED;
|
return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue