1

i am followin this tutorial frrom androidHive to intigrate GCM in my app.

in my previous project i have integrated GCM by following this blog. And that is working fine.

But, in my new project, this is not working. i am getting no data in my server. the only difference between this two project is: in my previous project , all my GCM related classes were in my project's default package. but in my new project the GCM related classes are in 'com.gcm' package, and i am calling them from another package's activity (which is my app's default package). i have track that (using Log.e) the code is executed to

//in -- MainActivity.java
// Check if regid already presents    
if (regId.equals("")) {    
    // Registration is not present, register now with GCM    
    GCMRegistrar.register(this, SENDER_ID);
    // after this nothing is happening
} else {

i have 'Log.e' in every classes and every possible places :( but they are not printing anything.

i think the service and receiver is not setted properly. so, i think i have to change in the manifest. but i don't no what to change. can anybody help me ?

the manifest from the blog:

In the following code replace all 'com.androidhive.pushnotifications'
with your android package name.

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidhive.pushnotifications"
    android:versionCode="1"
    android:versionName="1.0" >

    <!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <!-- GCM connects to Internet Services. -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- Creates a custom permission so only this app can receive its messages. -->
    <permission
        android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
        // i have changed 'com.androidhive.pushnotifications' to 'com.gcm' but getting error.
        // so i have rplace 'com.androidhive.pushnotifications' with my default package name.

    <uses-permission android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
    // i have changed 'com.androidhive.pushnotifications' to 'com.gcm' but not woeking

    <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Network State Permissions to detect Internet status -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <!-- Main activity. -->
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <!-- Register Activity -->
        <activity
            android:name=".RegisterActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Main Activity -->
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name" >
        </activity>

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.androidhive.pushnotifications" />
                                       // what will be this?
                                       // replace with default package or
                                          'com.gcm' package ?
            </intent-filter>
        </receiver>

        <service android:name=".GCMIntentService" /> 
                // i have change this to 'com.gcm.GCMIntentService'
    </application>

</manifest>

..

<permission
    android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
    // i have changed 'com.androidhive.pushnotifications' to 'com.gcm' but getting error.
    // so i have rplace 'com.androidhive.pushnotifications' with my default package name.

  <uses-permission    
       android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
       // i have changed 'com.androidhive.pushnotifications' to 'com.gcm' but not woeking

..

<service android:name=".GCMIntentService" /> 
    // i have change this to 'com.gcm.GCMIntentService'

..

<receiver
    android:name="com.google.android.gcm.GCMBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <!-- Receives the actual messages. -->
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <!-- Receives the registration id. -->
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        <category android:name="com.androidhive.pushnotifications" />
                            // what will be this?
                            // replace with default package or
                               'com.gcm' package ?
    </intent-filter>
</receiver>

EDIT: (SOLUTION)

as eran suggested the answer of this question, the solution is in the answer of the question.

Community
  • 1
  • 1
Shoshi
  • 2,254
  • 1
  • 29
  • 43
  • @Eran : thank you. this is the answer i was looking for. can you please post your comment as answer bellow, so that i can accept your answer ? – Shoshi Sep 02 '13 at 19:07

1 Answers1

0

I suggest follow the instructions from Google GCM's website instead : Google GCM Client Dev Guide

You should extend a broadcast receiver either from Google's GCMBroadcastReceiver, or WakefulBroadcastReceiver. In this extended receiver, define where your GcmIntentService class is. If Your GcmIntentService is not in your main package path, then you need to enter the package path.

azgolfer
  • 15,087
  • 4
  • 49
  • 46