Android GCM basic implementation

前端 未结 9 1917
鱼传尺愫
鱼传尺愫 2020-12-01 04:54

UPDATE: I fixed the problems in the code below so this makes a nice basic working example of how to use GCM


So, I\'m trying to im

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 04:54

    I think you have some issues in the code.

    You should do the registration of your own broadcast receiver in the manifest file and that receiver will trigger the .

    Therefore you must do something like I write below.

    • The receiver must be declared like:

      
          
              
              
          
      

    • Your broadcast receiver that will start the service.

      public class YourBroadCastReceiver extends BroadcastReceiver {
      
      @Override
       public final void onReceive(Context context, Intent intent) {
           GCMIntentService .runIntentInService(context, intent);
           setResult(Activity.RESULT_OK, null, null);
       }  
      }
      

    I advice you to take a look at the official GCM documentation where you can find a good example.

    And... don't forget to enable the Google Cloud Messaging service in the main Google APIs Console page.

    Let me know if it helps!

提交回复
热议问题