MEDIA_PROJECTION_SERVICE在对getSystemService()的调用中无效 [英] MEDIA_PROJECTION_SERVICE not valid in call to getSystemService()

查看:695
本文介绍了MEDIA_PROJECTION_SERVICE在对getSystemService()的调用中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to develop an application that requires the ability to capture screen content. I'm targeting lollipop to avoid the requirement for root. When trying to get an instance of the MediaProjectionManager via a call to getSystemService() I am getting the following error reported in 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指定为最小目标.还有其他明显/愚蠢的东西可能会导致此错误吗?

I am currently at a loss as to why this constant is not considered valid, it's there as an autocomplete option, so it's present, and it's shown in all sample code I have seen for screen capture in lollipop. I have verified that the project setup specifies Android SDK 21 as min and target. Is there something else obvious/stupid I might be missing that would cause this error?

更新:将完全相同的代码带到Eclipse,并且可以正常工作.因此,这似乎与Android Studio中的某些内容有关.

UPDATE: Took the exact same code to Eclipse and it works without issue. So this is related to something in Android Studio specifically it seems.

推荐答案

我在获取Context.BLUETOOTH_SERVICE时遇到此错误,并且错误文档(必须是其中之一.)包含Context.BLUETOOTH_SERVICE

I get this error while getting Context.BLUETOOTH_SERVICEand the error doc (Must be one of..) contains Context.BLUETOOTH_SERVICE though.

这不是Android Studio"1.2"的工作方式. :@

This is not the way Android Studio "1.2" should work. :@

无论如何,它是一个Inspection错误,Constant and Resource Type mismatch(蓝牙在Android上下文中到底是一种资源).

Anyway, its an Inspection bug, Constant and Resource Type mismatch (How in the hell Bluetooth is a resource in android context).

您可以在Class/Method/Statement,语句中取消此操作,在语句上方或之前添加@SuppressWarnings("ResourceType").

You can suppress this for Class/Method/Statement, for statement, add @SuppressWarnings("ResourceType") above or before the statement.

另一种方法:

转到 设置>>编辑器>>检查>> Android >>常量和资源类型不匹配 ,并将严重性设置为除Error以外的任何值,可能是WarningWeak Warning.

Goto Settings>>Editor>>Inspection>>Android>>Constant and Resource Type Mismatches and make the severity to anything but Error, probably Warning or Weak Warning.

(尽管它可以解决错误问题,但我希望这种不匹配在实际发生时成为错误.)

(Though it fixes the error issue, but I want this mismatch to be an error when it really happens.)

这篇关于MEDIA_PROJECTION_SERVICE在对getSystemService()的调用中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆