我的项目显示了WakefulBroadcastReceiver cannot be resolved to a type的错误消息。我查了一下我能想到的所有可能的原因。我已经设置了android-support-library和google play services的路径。即使是我的mapView工作(如果我在下面的代码注释),这意味着google play service被正确地添加到项目中。
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}知道为什么会出错吗?
发布于 2013-09-27 12:50:42
确保您的项目中添加了最新的Android支持包。例如,this sample project有一个合适的android-support-v4.jar,并演示了WakefulBroadcastReceiver的使用。
发布于 2013-09-30 07:26:55
这是由于android-support-v4.jar文件,请确保您有最新的。如果你认为你的项目中有它,那就做个小把戏吧。在另一个项目中找到相同的文件,比如用最新的SDK创建新项目。将它的jar文件复制到您的项目中,并替换旧的项目。现在导入import android.support.v4.content.WakefulBroadcastReceiver;并看到它正常工作。
发布于 2013-09-30 13:31:45
获取支持文件的最新版本。如果您正在使用Eclipse,请启动Android管理器(Window->)。在Extras->Android支持库下,您将看到是否有最新的修订版(如果没有,则表示更新可用)。更新后,包应该出现在这里: /extras/android/support/。
更多信息:http://developer.android.com/tools/support-library/setup.html
https://stackoverflow.com/questions/19051088
复制相似问题