1

I am integrating Pushwoosh API for push notifications for which I require deviceToken. How do I get it :

I am getting empty string using this :

String deviceToken=GCMRegistrar.getRegistrationId(getApplicationContext()); 

These are the permissions I have in my AndroidMainfest.xml :

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

<application ...>
    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.example.gcm" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmIntentService" />
</application>

Is this the right way to get deviceToken.

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • can you pl confirm , you have given internet permission in your manifest or your internet is accessible to your device or not –  Apr 03 '15 at 13:53
  • @AndroidWeblineindia : Yes I have. – Nitish Apr 03 '15 at 13:55
  • if possible can you pl provide code so better to understand where you have problem –  Apr 03 '15 at 14:01
  • @AndroidWeblineindia : This is the single line of code I am using for getting deviceToken. Nothing else. Mainfest premissions are same as Ashish has mentioned in his answer. – Nitish Apr 03 '15 at 14:05

2 Answers2

0

Your code is looking fine, just compare your AndroidManifest with below code to make sure you are not missing anything there -

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

<application ...>
    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.example.gcm" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmIntentService" />
</application>

Hope this helps :)

Ashish Tamrakar
  • 810
  • 10
  • 24
  • I don't have GcmIntentService anywhere in application. I am using the default GcmBroadcastReceiver. With that matter ? – Nitish Apr 03 '15 at 13:55
0

Try below code, hope it will help you

    GCMRegistrar.checkDevice(getApplicationContext());
    GCMRegistrar.checkManifest(getApplicationContext());    

    final String regId = GCMRegistrar.getRegistrationId(this);