android – MEDIA_PROJECTION_SERVICE在调用getSystemService()时无效

我正在尝试开发一个需要捕获屏幕内容的应用程序.我瞄准棒棒糖以避免对root的要求.通过调用getSystemService()尝试获取MediaProjectionManager的实例时,我在
Android Studio中报告了以下错误:

Must be one of: Context.POWER_SERVICE, Context.WINDOW_SERVICE, Context.LAYOUT_INFLATER_SERVICE, Context.ACCOUNT_SERVICE, Context.ACTIVITY_SERVICE, Context.ALARM_SERVICE, Context.NOTIFICATION_SERVICE, Context.ACCESSIBILITY_SERVICE, Context.CAPTIONING_SERVICE, Context.KEYGUARD_SERVICE, Context.LOCATION_SERVICE, Context.SEARCH_SERVICE, Context.SENSOR_SERVICE, Context.STORAGE_SERVICE, Context.WALLPAPER_SERVICE, Context.VIBRATOR_SERVICE, Context.CONNECTIVITY_SERVICE, Context.WIFI_SERVICE, Context.WIFI_P2P_SERVICE, Context.NSD_SERVICE, Context.AUDIO_SERVICE, Context.MEDIA_ROUTER_SERVICE, Context.TELEPHONY_SERVICE, Context.CLIPBOARD_SERVICE, Context.INPUT_METHOD_SERVICE, Context.TEXT_SERVICES_MANAGER_SERVICE, Context.DROPBOX_SERVICE, Context.DEVICE_POLICY_SERVICE, Context.UI_MODE_SERVICE, Context.DOWNLOAD_SERVICE, Context.NFC_SERVICE, Context.BLUETOOTH_SERVICE, Context.USB_SERVICE, Context.INPUT_SERVICE, Context.DISPLAY_SERVICE, Context.USER_SERVICE, Context.PRINT_SERVICE less... (Ctrl+F1) 

Reports two types of problems:
* Supplying the wrong type of resource identifier. For example, when calling Resources.getString(int id), you should be passing R.string.something, not R.drawable.something.
* Passing the wrong constant to a method which expects one of a specific set of constants. For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.

我目前不知道为什么这个常量不被认为是有效的,它作为一个自动完成选项存在,所以它存在,并且它显示在我看到的棒棒糖屏幕捕获的所有示例代码中.我已经验证项目设置将Android SDK 21指定为min和target.是否有其他明显/愚蠢的我可能会丢失会导致此错误?

更新:为Eclipse提供完全相同的代码,它没有问题.所以这与Android Studio中的某些内容有关.

最佳答案 在获取Context.BLUETOOTH_SERVICE和错误文档(必须是其中之一)时,我收到此错误,但包含Context.BLUETOOTH_SERVICE.

这不是Android Studio“1.2”应该工作的方式. :@

无论如何,它的检查错误,常量和资源类型不匹配(如何在地狱蓝牙是android上下文中的资源).

您可以对Class / Method / Statement,for语句抑制此项,在语句之上或之前添加@SuppressWarnings(“ResourceType”).

另一种方法:

转到设置>>编辑器>>检查>> Android>>常量和资源类型不匹配,并将严重性设置为除错误之外的任何内容,可能是警告或弱警告.

(虽然它修复了错误问题,但我希望这种不匹配在发生时才会出错.)

点赞