Git Product home page Git Product logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
The GCMConstants define a suffix for the intent service, which is appended to 
your app's default package.

If you need a different class name or package, you must extend 
GCMBroadcastReceiver and override the getGCMIntentServiceClassName() method to 
return the desired FQCN (Fully-Qualified Class Name).

If you have an user case that is not covered by this approach, please let us 
know.

Original comment by [email protected] on 23 Jul 2012 at 4:14

  • Changed state: WontFix

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Check this code. 

http://code.google.com/p/gcm/source/browse/gcm-client/src/com/google/android/gcm
/GCMRegistrar.java#285

Inside GCMRegistrar class, it uses GCMBroadcastReceiver directly. 
so I think erkasrim's patch is reasonable. Is'n it?

Original comment by [email protected] on 24 Jul 2012 at 1:56

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Thank your answer.

I know your suggest 
But!!! It is include bug!
Show this code 
<GCMRegistrar class code>

    public static void register(Context context, String... senderIds) {
        setRetryBroadcastReceiver(context);
        GCMRegistrar.resetBackoff(context);
        internalRegister(context, senderIds);
    }

    private static synchronized void setRetryBroadcastReceiver(Context context) {
        if (sRetryReceiver == null) {
            sRetryReceiver = new GCMBroadcastReceiver();
            String category = context.getPackageName();
            IntentFilter filter = new IntentFilter(
                    GCMConstants.INTENT_FROM_GCM_LIBRARY_RETRY);
            filter.addCategory(category);
            // must use a permission that is defined on manifest for sure
            String permission = category + ".permission.C2D_MESSAGE";
            Log.v(TAG, "Registering receiver");
            context.registerReceiver(sRetryReceiver, filter, permission, null);
        }
    }

register method is always call setRetryBroadcastReceiver
and setRetryBroadcastReceiver method is create the GCMBroadcastReceiver !!!

Look this is my AndroidManifest.xml file! and Custom GCMBroadcastReceiver class

I do not want define 'GCMBroadcastReceiver' in my AndroidManifest.xml file

        <!-- using GCM service -->
        <service android:name="net.daum.mf.push.gcm.GCMIntentService" />
        <receiver
            android:name="net.daum.mf.push.gcm.DaumGCMBroadcastReceiver"
            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="net.daum.mf.push.sample" />
            </intent-filter>
        </receiver>


public class DaumGCMBroadcastReceiver extends GCMBroadcastReceiver {

    private static final String TAG = "GCMBroadcastReceiver";

    @Override
    public final void onReceive(Context context, Intent intent) {
        Log.v(TAG, "onReceive: " + intent.getAction());
        String className = getGCMIntentServiceClassName(context);
        Log.v(TAG, "GCM IntentService class: " + className);
        // Delegates to the application-specific intent service.
        GCMBaseIntentService.runIntentInService(context, intent, className);
        setResult(Activity.RESULT_OK, null /* data */, null /* extra */);
    }

    /**
     * Gets the class name of the intent service that will handle GCM messages.
     */
    protected String getGCMIntentServiceClassName(Context context) {
        return "net.daum.mf.push.gcm.GCMIntentService";
    }
}

You know, an exception is raised!!!

And then, I need 'setGCMIntentServiceClassName' method!!!

Original comment by [email protected] on 24 Jul 2012 at 2:18

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
GCMRegistrar uses GcmBroadcastReceiver directly because it uses it to handle 
the retry logic. If you extend that class, your "main" receiver will be an 
instance of the extended class, while the "retry" broadcaster will be an 
instance of the base class, which is fine. Even if you don't extend it, there 
will be 2 instances anyways, as they require different permissions.

So, I still don't see the point of this patch. We could split the receivers in 
2 classes to make it clearer, but the overall code would be more complicated.

Original comment by [email protected] on 24 Jul 2012 at 2:58

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Inside 2nd instance of GCMBroadcastReceiver, it delegate intent to 
DEFAULT_INTENT_SERVICE_CLASS_NAME. 
if DEFAULT_INTENT_SERVICE_CLASS_NAME not exist, it will crash.

I think he want use his own service class name instead of 
DEFAULT_INTENT_SERVICE_CLASS_NAME

Original comment by [email protected] on 24 Jul 2012 at 3:41

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Ah, ok, makes sense, thanks for the clarification.

I will try to fix it without requiring a new method.

Original comment by [email protected] on 24 Jul 2012 at 6:15

  • Changed title: GCMBroadcastReceiver.onReceive() throws exception when receiving retry intent if app uses a custom intent service class
  • Changed state: Accepted

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Fixed on 
http://code.google.com/p/gcm/source/detail?r=8094cc6410b7dc2db452eb19cc9274fda1b
2d6a2 , will be available in the next release.

Please note that the new methods are used internally so this fix won't require 
any change in the apps.

Original comment by [email protected] on 27 Jul 2012 at 4:05

  • Changed state: Fixed

from gcm.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 23, 2024
Thanks~!!!

Original comment by [email protected] on 30 Jul 2012 at 6:35

from gcm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.