Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms android Application not getting DeviceToken Parse SDK

I'm developing xamarin forms application for both android and iOS. I'm implementing the PushNotifications for the same using Parse SDK. I've added Parse.Android dll in references of .Droid project and Parse.iOS dll in references of .iOS project. My problem is sometimes on Android I'm not able to retrieve the DeviceToken. There're no entries for DeviceToken and pushtype in the parse installation class. It's values are 'undefined'. Below is my code along with manifest.

public  async void RegisterForPushNotifications ()     {         try {             if (Utility.isNetworkConnected ()) {                 await ParsePush.SubscribeAsync ("");                 var installation = ParseInstallation.CurrentInstallation;                 // I'm saving the DeviceToken in App.regId for future uses                 App.regId = System.String.IsNullOrWhiteSpace (installation.DeviceToken) ? "" : installation.DeviceToken;                 ParsePush.ParsePushNotificationReceived += PushNotificationReceived;             }         } catch (ParseException e) {             System.Diagnostics.Debug.WriteLine (e.StackTrace);         } catch (Java.Lang.Exception e) {             e.PrintStackTrace ();         }     } 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.nirvaniclabs"> <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" /> <application android:label="RxLifetime" android:icon="@drawable/icon" android:largeHeap="true">     <receiver android:name="parse.ParsePushBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">         <intent-filter>             <action android:name="com.google.android.c2dm.intent.RECEIVE" />             <action android:name="com.google.android.c2dm.intent.REGISTRATION" />             <category android:name="com.nirvaniclabs" />         </intent-filter>     </receiver>     <service android:name="parse.ParsePushService" /> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.LOCATION_HARDWARE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:protectionLevel="signature" android:name="com.nirvaniclabs.permission.C2D_MESSAGE" /> <uses-permission android:name="com.nirvaniclabs.permission.C2D_MESSAGE" /> </manifest> 

Also some times above mentioned code is causing crashes at app startup. I've reported this issue here and here

Also ParseClient.Initialize is the very first line of 'OnCreate' method of MainActivity where I'm passing parse keys required for initialization.

I'm calling RegisterForPushNotifications method after LoadApplication (new App ()) is called.

Attached below is the screenshot of parse installation class.

parse installation

Please let me know if there's some issue in my code or is it the issue with parse SDK.

like image 450
Amrut Avatar asked Sep 17 '15 07:09

Amrut


1 Answers

when you have declare the push notification using xamarin then you have to write code on both section like xamarin android and IOS, and also if you have used to remote notification then use to push sharp lib which is a best for push notification and register your app and enable to notification service like GCM and APSN relevent to android and IOS.

Plese try this : https://github.com/rdelrosario/xamarin-plugins/tree/master/PushNotification/PushNotification

like image 56
Vimal Kotadia Avatar answered Oct 08 '22 22:10

Vimal Kotadia