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.
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?
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.
I get this error while getting Context.BLUETOOTH_SERVICEand the error doc (Must be one of..) contains Context.BLUETOOTH_SERVICE though.
This is not the way Android Studio "1.2" should work. :#
Anyway, its an Inspection bug, Constant and Resource Type mismatch (How in the hell Bluetooth is a resource in android context).
You can suppress this for Class/Method/Statement, for statement, add #SuppressWarnings("ResourceType") above or before the statement.
Another approach:
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.)
Run into the same problem, it is so strange, there are no any other threads talking about this problem.
Well, actually you can just ignore this error and still run the program, even with
the red marks on it
Related
I have tested the application on my device and few emulators. The app doesn't crash and I don't see anything on the LogCat but I can see around 400 crashes within 22 hours in ANRs & crashes.
The error doesn't say which resource is missing to check it and if it's missing why it is not crashing on my phone?
This is the line which causes the crash:
int themeLayout = sharedPreferences.getInt(THEME_KEY, R.layout.input_1);
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
themeLayout, null);
If shared preference returns null then I assigned a default value to use that one but still, it crash. I checked the layout and it exists, also check the content.
I created the emulator with the same specification but it doesn't crash.
android.content.res.Resources$NotFoundException: at
android.content.res.ResourcesImpl.getValue (ResourcesImpl.java:202)
at android.content.res.Resources.loadXmlResourceParser
(Resources.java:2968) at android.content.res.Resources.getLayout
(Resources.java:1984) at android.view.LayoutInflater.inflate
(LayoutInflater.java:425) at android.view.LayoutInflater.inflate
(LayoutInflater.java:378) at
com.sunzala.afghankeyboard.android.SoftKeyboard.onCreateInputView
(SoftKeyboard.java:163) at
com.sunzala.afghankeyboard.android.SoftKeyboard.onStartInput
(SoftKeyboard.java:242) at
android.inputmethodservice.InputMethodService.doStartInput
(InputMethodService.java:2641) at
android.inputmethodservice.InputMethodService$InputMethodImpl.startInput
(InputMethodService.java:590) at
android.inputmethodservice.IInputMethodWrapper.executeMessage
(IInputMethodWrapper.java:186) at
com.android.internal.os.HandlerCaller$MyHandler.handleMessage
(HandlerCaller.java:37)
Edit:
I found this error:
E/dalvikvm: Could not find class
'android.graphics.drawable.RippleDrawable', referenced from method
android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
The R values that we refer to in Java code, such as R.layout.input_8, are public static final int values on a code-generated R class. You will find that class in the build/generated/source/r/ directory of your module. The file will be fairly large, but you will see stuff like:
public static final class layout {
public static final int activity_main=0x7f050000;
}
That number (0x7f050000) is generated by the build tools (aapt, specifically, IIRC). And that value can change from build to build. As a result, it is not safe to persist such a number. Otherwise, you wind up with scenarios like this:
User installs your app
User does something in your app that causes you to persist a value (e.g., editor.putInt(THEME_KEY, R.layout.input_8).apply();)
Time passes
You ship an update to your app, where, as it turns out, the number for R.layout.input_8 changes
The user installs the update to your app
Your code calls sharedPreferences.getInt(THEME_KEY, R.layout.input_1); and retrieves a number that used to be a resource ID... but now is just a number, or points to some different resource
Your code crashes
The user gets frustrated and throws their phone against a wall
Note: no actual phones or walls were harmed in the creation of this scenario
This is a problem with your code. I do not know if it is the problem that is triggering your crashes, but it could be.
The problem is that you are persisting a value (0x7f050000) that you do not control. You think that R.layout.input_8 will always be 0x7f050000, but that is not the case.
What you need to do is store something else in the preference, then use that to look up the proper ID. There are two main approaches for this.
One is to use a simple index. Your naming scheme suggests that you have a series of numbered layouts, at least through 8. So, you could save a number between 1 and 8 in the SharedPreferences, then use that as an index into an array:
static final int[] THE_LAYOUTS={R.layout.input_1, R.layout.input_2, R.layout.input_3, R.layout.input_4, R.layout.input_5, R.layout.input_6, R.layout.input_7, R.layout.input_8};
In this solution, editor.putInt(THEME_KEY, R.layout.input_8).apply(); turns into editor.putInt(THEME_KEY, 8).apply();, and sharedPreferences.getInt(THEME_KEY, R.layout.input_1); turns into THE_LAYOUTS[sharedPreferences.getInt(THEME_KEY, 1)];.
The other is to save the string "R.layout.input_8". Given that, and getIdentifier() on a Resources object, you can get back the int value associated with that string for your current build. Personally, I find this to be more awkward and slower, but it's an option.
I am facing these problems when integrating slide menu library in Android Studio(1.1.0) project. I am using sdk 24.1.2.
The error is at line 63 in the code given below:
super(act, R.id.menu_label, items);
However i have integrated this library in one of my eclipse project & no error has been evolved there.
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.
Did anyone has experience with MVEL2 on android?
i've tried out the same code with a simple java program and later on android:
The following exception is thrown when executed on android:
E/AndroidRuntime(30793): java.lang.ExceptionInInitializerError
I tried the example from the mvel website:
String template = "Hello, my name is #{name.toUpperCase()}";
Map vars = new HashMap();
vars.put("name", "Michael");
System.out.println(TemplateRuntime.eval(template, vars));
If theres no solution could anyone suggest a template engine which works with android
and supports iteration?
MVEL2 tries to substring the first 3 characters of the system java.version property when initializing the parser, and under Android the version is 0. That causes a bunch of exceptions which eventually cause the ExceptionInInitializerError.
If you want to force the java.version property, you can simply set it yourself:
System.setProperty("java.version", "1.6");
I have no idea what kind of odd side effects this may cause for Android, but at least it gets the MVEL parser up and running without throwing exceptions!
System.setProperty with "java.version" key seems to be read only propery in android, so it won't work.
i've tried to integrate MVEL 2 into android with no success, try using EVAL lib
I am tring to get an xml doc in my appBut I am getting an error in getTextContent() as "method getTextContent() is undefined for the type Node".I have also added the required packages at the top for it.I have also tried xml-apis-1.0.b2.jar & tried the quick fix of casting it also. I have add this part of this code,
fullReport.append(docs.getElementsByTagName("report").item(0).getTextContent());
Please tell me how can I correct this one.Thanks a million mate.
The one reason may be is that getTextContent () is not defined under type Element dut to the fact your Android project target version should be less than 2.2.It is only available in the higher version of Android to enhance the lower version.Just try updating your version 2.2 or more.Cheers!!!
Maybe because the order of the imports. Take a look at http://www.enterprisesearchblog.com/2009/09/fix-for-gettextcontent-is-undefined-for-the-type-node-for-solr-project-in-eclipse-ide.html
I'm working on one of my android widgets, which uses LauncherPlus to add scrolling functionality, and am running into a frustrating issue. My currently published version of the code, again using LauncherPlus, is working well, scrolling and all. I'm adding a requested feature, one which allows changing text sizes, but an exception is thrown when I test the update. There exception is:
mobi.intuitit.android.widget.SimpleRemoteViews$ActionException: can't find view:0x7f070041
I haven't changed anything in the layouts and the only code change references a view id which was already referenced in that same section of code. I looked through the R.java and found which resource was referred to and again, nothing has changed there. Here's the bit of code where the issue is coming from:
itemViews.setBoundBitmap(R.id.profile, "setImageBitmap", SonetProvider.SonetProviderColumns.profile.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.friend, "setText", SonetProvider.SonetProviderColumns.friend.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.created, "setText", SonetProvider.SonetProviderColumns.createdtext.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.message, "setText", SonetProvider.SonetProviderColumns.message.ordinal(), 0);
The exception is thrown when applying the first line. Out of curiosity, I changed the order of these lines, and each one of them will cause the exception, though again, the layout hasn't changed. After the exception is thrown the widget will build successfully, but I can't publish this update with an exception (force close) being thrown. Any ideas why there is a resource issue? Thanks!
UPDATE:
I found this discussion where it seems that widget resources may not be reloaded on application updates:
http://groups.google.com/group/android-developers/browse_thread/thread/55a8e44974e8c6ad?fwc=1&pli=1
Does anyone have any experience with this, or a workaround? This may be what I'm facing.
Use Project > Clean in Eclipse or ant clean from the command line, then try again. Since resource IDs are integers, they are inlined in the bytecode of the classes that reference them, and so sometimes your pre-compiled classes can get out of sync with new resource IDs from a fresh compile. I work from the command line mostly, and I always tack clean onto my ant commands (e.g., ant clean install) to avoid this problem.