My project shows error message that WakefulBroadcastReceiver cannot be resolved to a type
.
I looked up for all possible reasons I can think of. I have set android-support-library
and google play services
's path. Even my mapView works (if I comment below code) that means google play service
is correctly added to project.
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);
}
}
Any idea why this gives error?
I had this problem today here's how I fixed it:
It's due to the Android Support JAR not being updated like the SDK manager one. You can delete it from your libs folder then do this:
Here 's a screenshot
Then go back to your class hit Ctrl + Shift + O
It will import your missing library:
import android.support.v4.content.WakefulBroadcastReceiver;
Project > Clean
and Voilà !!
Make sure that you have the latest Android Support package added to your project. For example, this sample project has a suitable android-support-v4.jar
and demonstrates the use of WakefulBroadcastReceiver
.
It's because of android-support-v4.jar
file, make sure you have the latest. If you think you have it in your project just do a trick. Find same file in another project, say create new project with latest SDK. Copy it's jar file into your this project and replace the older one. Now import import android.support.v4.content.WakefulBroadcastReceiver;
and see it working..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With