Cannot Resolve ContextCompat in Android

cannot resolve symbol activitycompat
contextcompat getdrawable
contextcompat vs resourcescompat
xamarin contextcompat
contextcompat getstring
error: package android.support.v4.content does not exist
didn 't find class android support-v4/content/contextcompat
react native import android support v4 content contextcompat

I have an AlertDialogue object called dialog. I am attempting to add an icon to it. I see that this syntax is now deprecated:

dialog.setIcon(getResources().getDrawable(R.drawable.myImage);

I'm reading everywhere that this should work:

dialog.setIcon(ContextCompat.getDrawable(context, R.drawable.myImage));

However, the ContextCompat syntax is not being recognized by Android Studio. Is there something that I should be importing? Thank you.

***Update: Thank's to @Sharj for the correct answer below. I made a quick video too if you guys need a visual: https://www.youtube.com/watch?v=eFiaO0srQro&feature=youtu.be

ContextCompat is part of support library v4. Have you added support library 4 to your project?

android.support.v4.content.ContextCompat

You can include support library to your build.gradle file under app folder if you haven't already

dependencies {
// other stuff here
    compile 'com.android.support:support-v4:23.0.0'
// update the 23.0.0 to latest version available

}

Cannot Resolve Symbol AppCompatActivity , Cannot Resolve Symbol AppCompatActivity, Cannot Resolve Symbol ContextCompat · android android-studio gradle android-gradle-plugin build.​gradle. Cannot resolve symbol ContextCompat.checkSelfPermission() Android Studio 3.1 Cannot Resolve Symbol (Themes, Widget, attr, etc.) Hot Network Questions

androidx.core.content.ContextCompat

from AndroidX dependency

implementation 'androidx.appcompat:appcompat:1.1.0'

Android - Getting ContextCompat to Work, How to import ContextCompat in to your Android Project in order to set an icon within your Duration: 1:55 Posted: Dec 25, 2016 In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI,

I had the same issue and this and a few more posts helped me. With Android studio you have multiple Gradle files.

I got my code to work by adding the dependencies section into Gradle (Module : Library) or the file that has "android {" ...

dependencies {
        // other stuff here
        compile 'com.android.support:support-v4:23.+'
        // update the 23.0.0 to latest version available
    }

Can´t found android.support.v4.content.ContextCompact, Version of the system, for this function I have to request permissions with ContextCompat.checkSelfPermission. When you create an android  Android: ContextCompat.getColor (context, R.color.my_color), can not resolve & ldquo; GetColor & rdquo; I know there are several similar questions regarding this has been asked here, however none of the solutions worked for me.

If you are using Android gradle plugin 3.0.1, add google() to your allProjects repositories in the build.gradle file (project level) then sync

like this:

allprojects {
    repositories {
        google()
        ....
        //other repos
    }
}

ContextCompat, ContextCompat. Kotlin |Java. public class ContextCompat ColorStateList, A color state list, or null if the resource could not be resolved. The problem is that Android Studio says Cannot resolve method 'checkSelfPermission'. I already included the appcompat and support lib. ContextCompat is known to AS but the method itself isn't known. I don't know what am I doing wrong - in another project I can write this method and it gets recognized.

Adding this to build.gradle(Module:App) under dependencies resolved the problem

compile 'com.android.support:support-v4:23.0.0'

Unable to resolve imports from Android Support Repository · Issue , LocalBroadcastManager) into the Android app of my Flutter app, IntelliJ is unable to Cannot resolve Symbol 'LocalBroadcastManager'. I used the Android SDK Manager to install the Android Support Repository. When I now try to import something from there (e.g. android.support.v4.content.LocalBroadcastManager) into the Android app of my Flutter app, IntelliJ is unable to resolve it: Cannot resolve Symbol 'LocalBroadcastManager' The app compiles just fine with that import though.

error: cannot find symbol import android.support.v4.app , error: cannot find symbol import android.support.v4.app. symbol: variable ContextCompat location: class AudioRecorderManager 3 errors  I also experienced this, but only when building using gradle directly (running react-native run-android built successfully without issues. I realised this is because run-android runs jetify as part of the build. If you're using ./gradlew assembleRelease, you need to run manually. npx jetify or if you're using yarn. yarn jetify

Java Code Examples android.support.v4.content.ContextCompat, This page provides Java code examples for android.support.v4.content.​ContextCompat. The examples are extracted from open source Java projects. Java Code Examples for android.support.v4.content.ContextCompat. The following are top voted examples for showing how to use android.support.v4.content.ContextCompat. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.

Class androidx.core.content.ContextCompat, ContextCompat android.support.v4.content. protected ContextCompat(). This class should not A color state list, or null if the resource could not be resolved. I'm writing an Android Wallpaper app in Flutter and when I call the Android Platform Code to set the wallpaper I need to show a Snackbar from the Platform Side (Not from the Flutter side). The Android Studio compiler cannot recognize Snackbar because it is part of the Android Support Library so I added the following line in app/build.gradle.

Comments
  • Could you please tell me how to add support library 4. Is it a simple import statement at the top of my class? import android.support.v4.content.ContextCompat
  • Also, which gradle file do I add the statement to? The one under build.gradle says Do not place your application dependencies here; they belong in the individual module build.gradle files.
  • You will find build.gradle file in your app folder.
  • @neuman8 I will advise to get Android Studio. Eclipse isn't support anymore for Android development.
  • @neuman8 I am sorry if it wasn't helpful. Here's Google's own words in June 2015 "Support for the ADT in Eclipse has ended. You should migrate your app development projects to Android Studio as soon as possible." developer.android.com/tools/help/adt.html
  • For newer versions use implementation and not compile
  • change compile to implementation. compile has been deprecated and replaced by implementation in recent version of android studio.