Je développe une application utilisant mono pour Android et j'ai eu du mal à faire fonctionner les notifications push, j'utilise Urban Airship.Utilisation de JNI dans Mono pour accéder à la bibliothèque Java
Jusqu'à présent, j'ai pu appeler TakeOff() et EnablePush() et mon application enregistre avec succès, consultez le code suivant:
//_____________________________
// Get the airship config class
IntPtr ip_airshipConfigOptions = JNIEnv.FindClass("com/urbanairship/AirshipConfigOptions");
if (ip_airshipConfigOptions == IntPtr.Zero)
{
throw new InvalidOperationException("Counldn't find java class !");
}
//__________________________________________________
// Get the loadDefaults method from the config class
IntPtr methodId = JNIEnv.GetStaticMethodID(ip_airshipConfigOptions, "loadDefaultOptions", "(Landroid/content/Context;)Lcom/urbanairship/AirshipConfigOptions;");
if (methodId == IntPtr.Zero)
{
throw new InvalidOperationException("Couldn't find java class !");
}
//________________________________________________________________
// Call the loadDefaultOptions method passing in this app instance
var methodPtr = JNIEnv.CallStaticObjectMethod(ip_airshipConfigOptions, methodId, new JValue(this));
//________________________
// Get the UAirship class
IntPtr ip_uairship = JNIEnv.FindClass("com/urbanairship/UAirship");
if (ip_uairship == IntPtr.Zero)
{
throw new InvalidOperationException("Couldn't find java class !");
}
//___________________________________________
// Get takeOff method with configoption param
IntPtr methodId2 = JNIEnv.GetStaticMethodID(ip_uairship, "takeOff", "(Landroid/app/Application;Lcom/urbanairship/AirshipConfigOptions;)V");
//______________________________________________
// Get takeOff method without configoption param
//IntPtr methodId3 = JNIEnv.GetStaticMethodID(ip_uairship, "takeOff", "(Landroid/app/Application;)V");
//___________________________________________________________________________________________
// Call UAirship.takeOff(this, options). Not sure if these parameters are specified correctly
JNIEnv.CallStaticVoidMethod(ip_uairship, methodId2, new JValue(this), new JValue(methodPtr));
//________________________________________
// Enable Push in Urban Airship Pushmanager
IntPtr ip_pushmanager = JNIEnv.FindClass("com/urbanairship/push/PushManager");
IntPtr ip_enablePush = JNIEnv.GetStaticMethodID(ip_pushmanager, "enablePush", "()V");
JNIEnv.CallStaticVoidMethod(ip_pushmanager, ip_enablePush);
Je dois maintenant faire un appel à PushManager.shared () .setIntentReciever (myClass) mais je n'arrive pas à accéder à la classe shared() ou à la méthode setIntentReciever. J'ai essayé différentes combinaisons pour essayer d'accéder à la méthode mais je continue à obtenir des exceptions de classe/méthode non trouvées.
//IntPtr ip_setReciver = JNIEnv.GetStaticMethodID(ip_PushManager, "shared().setIntentReceiver", "(Landroid/app/Class)V");
Toute aide avec ceci est appréciée! Je suis sûr qu'il peut être résolu avec une ligne, je pense que je manque juste quelque chose avec la syntaxe.
Cordialement
Juste pour référence, l'appel de java ressemble à ceci:. PushManager.shared() setIntentReceiver (IntentReceiver .classe); – Adrian