gpt4 book ai didi

android - 使用 Asynctask 进行 GCM 注册时出错

转载 作者:太空宇宙 更新时间:2023-11-03 11:58:53 25 4
gpt4 key购买 nike

我正在使用来自开发者网站的相同代码,但在编译时出错。 http://developer.android.com/google/gcm/gs.html

复制下面的代码

private void registerBackground() {
new AsyncTask() {
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
regid = gcm.register(GCM_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.

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

// Save the regid for future use - no need to register again.
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PROPERTY_REG_ID, regid);
editor.commit();
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
// Once registration is done, display the registration status
// string in the Activity's UI.
@Override
protected void onPostExecute(String msg) {
mDisplay.append(msg + "\n");
}
}.execute(null, null, null);
}

我在编译时收到错误消息“Asynctask 是一种原始类型。对泛型类型的引用应该被参数化。

最佳答案

您还没有声明泛型类型参数。

改变

new AsyncTask() {

new AsyncTask<Void,Void,String>() {

还有,

execute(null, null, null);

可以改成

execute();

关于android - 使用 Asynctask 进行 GCM 注册时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16762228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com