Android Studio中不能使用棒棒糖特定的类 [英] Can't use Lollipop specific classes in Android Studio
问题描述
我有一个 minSdk 21
项目,棒棒堂
问题的具体类。
这是我的 gradle.build
I'm having problems with Lollipop
specific classes in a minSdk 21
project.
This is my gradle.build
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.mypackage"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
当我尝试使用 UsageStatsManager
我从<$ C $一个'无法解析符号UsageStatsManager
错误C> Android的工作室。
或者,如果我使用 Context.JOB_SCHEDULER_SERVICE
/ Context.USAGE_STATS_SERVICE
常量是找不到的。
When I try to use UsageStatsManager
I get a 'Cannot resolve symbol UsageStatsManager'
error from Android Studio
.
Or if I use Context.JOB_SCHEDULER_SERVICE
/Context.USAGE_STATS_SERVICE
the constant isn't found.
这是一个例子类,它给了我这些错误。
This is an example class that gives me these errors.
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.usage.UsageStatsManager;
import android.app.job.JobScheduler;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UsageStatsManager mUsageStatsManager = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
JobScheduler mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
}
在这种情况下,即使是导入
为 UsageStatsManager
失败,出现错误'无法解析符号UsageStatsManager
,而的jobscheduler
被找到(但因为我有我可以不使用它没有 Context.JOB_SCHEDULER_SERVICE
)
In this case even the import
for UsageStatsManager
fails with the error 'Cannot resolve symbol UsageStatsManager'
, while the JobScheduler
is found (but I can't use it because I have no Context.JOB_SCHEDULER_SERVICE
)
我已经下载从 SDK管理器
,我都在<$ C $ 的android-21
平台C>源和 SDK
。
I've downloaded android-21
platform from the SDK Manager
, I have both the source
and the SDK
.
我缺少的东西吗?
推荐答案
来自旧安装的Android工作室的东西是造成问题,所以我也跟着的这个答案并删除缓存。现在它的工作原理。
Something from an old installation of Android Studio was causing problems, so I followed this answer and deleted the caches. It now works.
这篇关于Android Studio中不能使用棒棒糖特定的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!