Hi I am trying to implement GCM push notification. I am getting an empty GCM id. Here is my code:
public void registerClient() {
try {
// Check that the device supports GCM (should be in a try / catch)
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
registrationStatus = "Registering...";
GCMRegistrar.register(this, PROJECT_ID);
regId="sfsaas";
regId = GCMRegistrar.getRegistrationId(this);
registrationStatus = "Registration Acquired";
Log.i("******IN_IF_REGID*****", regId);
Log.i("INSIDE","if");
}
else
{
Log.i("INSIDE","else");
registrationStatus = "Already registered";
Log.i("******REGID*****", regId);
}
}
catch (Exception e) {
e.printStackTrace();
registrationStatus = e.getMessage();
}
}
Here is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eventnotifier"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.eventnotifier.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="com.example.eventnotifier.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Camera permission -->
<uses-feature android:name="android.hardware.camera" />
<!-- receives GCM messages -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google services -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<!-- wake the processor if a GCM message is received -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:color/black" >
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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.example.eventnotifier" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
<activity
android:name="com.example.eventnotifier.HomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.eventnotifier.RegisterActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.eventnotifier.DateActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.DescriptionActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.MyEventActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.CreateEventActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.LocationActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.AddGuestActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.ContactListActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.ContactTest"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.InvitedGuestsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.MyInvitationsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.UnregisteredGuestsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.eventnotifier.RecentGuestsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
This line is not getting printed -Log.i("**IN_IF_REGID***", regId); Can you guys help me out? I have to submit this project tomorrow. Any help will be appreciated! Thank you