4

I have a project class with the following imports:

import android.app.Activity;
import android.app.Fragment;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

In android studio the following three bring up a 'cannot resolve symbol' error:

import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;

Wierdly, the import for NotificationCompat and NotificationCompat.Action in android.support.v4.app are successful

import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;

I have tried to use the same imports on eclipse (pointing to the same SDK as android studio) and the same worked and ran without any errors.

I've also tried Minto's solution of invalidating caches/restarting android studio ...my SDK is up to date as at the time of posting. Thanks for any help in advance

Community
  • 1
  • 1
Tom
  • 43
  • 2
  • 6

2 Answers2

6

Make sure that you put the following entry into your application's build.gradle file to provide the necessary dependencies:

dependencies {
    compile 'com.android.support:support-v4:20.0+'
}

The version number is important, if you specify an older version it will be missing the new Notification code for wearables.

Wayne Piekarski
  • 3,203
  • 18
  • 19
  • Thanks for the pointer; I checked out my build.gradle and android studio suggested that I use `com.android.support:support-v4:21.0.0+`, from there everything worked like magic :-) – Tom Jul 11 '14 at 03:04
2

Google has moved some of these tools into the standard libraries. For example, WearableExtender is in Android.app.Notification now. Try ditching the import statements giving you problems, and let Android Studio suggest what to import. Lots of Google's guides have outdated or otherwise incorrect code right now, as they have recently rolled out Google Play Services 5 and other official releases of preview products.

nickjm
  • 412
  • 1
  • 10
  • 21
  • Thanks, this worked for me after I updated my build.gradle file to include `com.android.support:support-v4:21.0.0+` rather than v20.0+ as in the answer by @Wayne – Tom Jul 11 '14 at 03:02