Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WakefulBroadcastReceiver cannot be resolved to a type

Tags:

java

android

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?

like image 659
Geek Avatar asked Sep 27 '13 12:09

Geek


3 Answers

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:

  1. right click project
  2. Go to Android Tools
  3. Add Support Library

Here 's a screenshot enter image description here

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à !!

like image 90
meda Avatar answered Sep 30 '22 20:09

meda


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.

like image 38
CommonsWare Avatar answered Sep 30 '22 21:09

CommonsWare


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..

like image 36
Saqib Avatar answered Sep 30 '22 20:09

Saqib