こんにちは、Android の公式ドキュメントに従ってプッシュ通知を送信しています。古い方法は非推奨ですが、GCM クライアントの実装で問題に直面しています。
http://developer.android.com/google/gcm/client.html
チュートリアルはここに書かれています。下にスクロールして見てください
private void registerInBackground()
アプリでこの関数を書くと、このエラーが発生します
Syntax error on token "void", @ expected
私はそれをグーグルで検索しましたが、このメソッドがメソッド内にメソッドを作成しようとしているというエラーを知っていますが、それは公式ドキュメントであるため、まだ混乱しています。このチュートリアルの方法は次のとおりです。
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.
}
}
sendRegistrationIdToBackend がメソッド自体の中にあることがわかりました。