2013-11-26 28 views
0

我下面由谷歌提供Android的GCM教程中,我也得到了以下錯誤:上線的Android GCM:上sendRegistrationIdToBackend語法錯誤令牌無效

:在令牌

private void sendRegistrationIdToBackend() { 
    // Your implementation here. 

} 

語法錯誤「無效」,@預計。

語法錯誤插入「枚舉標識符」來完成EnumHeader。

使用編譯器1.6

非常感謝。

整個功能:

private void registerInBackground() { 
    new AsyncTask() { 
     @Override 
     protected String doInBackground(Void... params) { 
      String msg = ""; 
      try { 
       if (gcm == null) { 
        gcm = GoogleCloudMessaging.getInstance(context); 
       } 
       regid = gcm.register(SENDER_ID); 
       msg = "Device registered, registration ID=" + regid; 

       // You should send the registration ID to your server over HTTP, 
       // so it can use GCM/HTTP or CCS to send messages to your app. 
       // The request to your server should be authenticated if your app 
       // is using accounts. 
       sendRegistrationIdToBackend(); 

       // For this demo: we don't need to send it because the device 
       // will send upstream messages to a server that echo back the 
       // message using the 'from' address in the message. 

       // Persist the regID - no need to register again. 
       storeRegistrationId(context, regid); 
      } catch (IOException ex) { 
       msg = "Error :" + ex.getMessage(); 
       // If there is an error, don't just keep trying to register. 
       // Require the user to click a button again, or perform 
       // exponential back-off. 
      } 
      return msg; 
     } 

     @Override 
     protected void onPostExecute(String msg) { 
      mDisplay.append(msg + "\n"); 
     } 
    }.execute(null, null, null); 
    /** 
    * Sends the registration ID to your server over HTTP, so it can use GCM/HTTP 
    * or CCS to send messages to your app. Not needed for this demo since the 
    * device sends upstream messages to a server that echoes back the message 
    * using the 'from' address in the message. 
    */ 
    private void sendRegistrationIdToBackend() { 
     // Your implementation here. 

    } 
} 
+1

請將所有代碼放在函數所在的位置。 – AlexBcn

+0

@AlexBcn我已更新帖子,謝謝 – Kourosh

回答

0

看來你忘了關registerInBackground()方法。

添加}}.execute(null, null, null);

另一種方式來看待它是你把private void sendRegistrationIdToBackend() {}registerInBackground()方法,這是不對的內部。

相關問題