Hi!
I am using xamarin android 4.10.1 and GooglePlayServices Rev. 12 from xamarin component store. It is mvvmcross application, so I have Core and Android projects. I need push notifications support in my app. So I start with GooglePlayServices component. I write this code:
var gcm = GoogleCloudMessaging.GetInstance(this); var key = gcm.Register(new[] { "senderId" });
and it doesn't work, I fount that I need to run it on async thread, one solution I found here: http://forums.xamarin.com/discussion/8420/error-calling-googlecloudmessaging-register
ThreadPool.QueueUserWorkItem(o => { var gcm = GoogleCloudMessaging.GetInstance(this); var key = gcm.Register(new[] { Settings.GmcSenderId }); });
This code works, my service handle registration message, but I need this registration key in my mvvmcross ViewModel. So I start to register with Task approach:
var task = Task.Factory.Startnew(() => { var gcm = GoogleCloudMessaging.GetInstance(this); return gcm.Register(new[] { Settings.GmcSenderId }); }); var key = task.Result; // wait for result // key is needed to execute code here // ViewModel.Key = key;
But every time I receive SERVICE_NOT_AVAILABLE Exception, also I have try to sync with ManualResetEvent object, but still have exceptions.
Maybe some one know solution, how to bring registration Id to ViewModel class from View (activity). Or maybe you have some example with mvvmcross and receiving registration Id in view model...
Posts
Detailed exception:
Are you testing on an Emulator?
Using phone with android 4.2.2. In project used API 16
Hello
We have new Google Play Services libraries available at
Google Play Services
Google Play Services (Gingerbread)
Google Play Services (Froyo)
Alex
Hi!
Still have same issue with registration. My main goal is to know registration id returned from google server. And I can't do this ( Now I am using google play services v15 (JB) library from xamarin components store. Same exceptions occurs.
One of the last codes:
The same exception Java.IO.IOException - SERVICE_NOT_AVAILABLE.
Spent 2 days on this... Will be glad for any suggestion
Hi @sachok,
I have the same issue. I found a workaround. It works but I feel it is totally wrong. Here is my solution:
Create a static WrapperClass and a inner ValuesClass class for sharing values:
Create a static HelperClass for registering devices to GCM service:
Actually this logic has a bug. The Thread in the Task needs to be checked whether it has finished it's job or not.
This approach could be done by a single static variable but I believe that the WrapperClass logic is more flexible for data processing.
By the way either GCM's Register or Unregister methods needs to be run in a Thread. System.Threading.Tasks.Task causes Java.IO.Exception exception (inner message is SERVICE_NOT_AVAILABLE) exception.
This approach works on either emulator or real device.
I know this thread is old but it seems that the issue is still here (or I am doing something wrong).
I hope XT or somebody will show the right way.