Android - XML Accessbility Service won't build - android

I have written a very simple accessibility service, the code works fine without an xml file defined for metadata but I want to add the xml file for compatibility purposes.
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:notificationTimeout="100"
android:description=""
/>
However the error I'm getting is none of the 'android:' resources are defined and also I'm not allowed that description. Although the description happens regardless of what I type or in what string asset I prove.
Anyone have any ideas..

Here it says android 4.0 has the option to configure the accessibility service with xml. Are you using 4.0+?
Also it mentions certain configuration options like canRetrieveWindowContent are only available when using the XML configuration. Are you using such options? If not, I don't think you really need the XML configuration.

It needs the xmlns portion....

Thanks for the suggested solutions. Turns out that you need to have your target build at 14 for eclipse to accept that xml file.

Related

Android: How to tell ShrinkResources to keep certain resources

I have an mp3 and an ogg file in my res/raw folder which I used with Android Media Player. I used setDataSource like so
musicPlayer.setDataSource(context, Uri.parse("android.resource://com.me.myapp/" + R.raw.music));
This works fine when running from Android Studio, however, when exporting a signed APK with shrinkResouces enabled, it strips out the mp3 (as mentioned above, I also have an ogg file which I use in the same way and which also gets stripped out). Here is the associated results in the Resouces.txt file:
Skipped unused resource res/raw/music.mp3: 485531 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/raw/oggmusic.ogg: 5335764 bytes (replaced with small dummy file of size 0 bytes)
I've done some research and there is a bug report on the Google Issue Tracker for this problem, however the poster says he/she used the information contained in the above link to make sure the required resources were not removed and the issue has been marked as 'intended behaviour' (which I find a little odd as I wouldn't have thought it would be intended behaviour for required resources to be removed).
Anyway, I've tried to do as mentioned in the docs and it doesn't seem to work, what am I doing wrong here? I've created an xml file called 'keep.xml' and placed it into my raw folder alongside the resources to keep.
This is the XML:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/*.mp3, #raw/*.ogg"/>
This issue wasn't evident in Eclipse, but has appeared since migrating to Android Studio.
EDIT
I did a bit more testing and I can confirm that whatever I specify in the XML file is being completely ignored. If I use "discard" for example instead of, or in place of 'keep', the resources stated in 'discard' appear in the generated APK file, so I must be doing something wrong or missing a step out somewhere.
I just experienced this issue and have found out what I was doing wrong.
Do not specify file extensions when referring to resources.
What I did at first (this will not work):
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/vid.mp4"
/>
Solution, drop the file extension:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/vid"
/>
You can verify this by inspecting the resources.txt file that you can find at ./app/build/outputs/mapping/<buildType>/resources.txt
https://developer.android.com/studio/build/shrink-code

Xamarin.Android attributes showing "not declared"

I am new to Xamarin and especially xml, but I have run into a problem that I have not been able to resolve with any solution after hours of searching. I am trying to use the "android.support.percent" package to use percent margins on a relative layout. I have installed the proper NuGet packages to support it too. It worked for a little while, but now it has suddenly started giving me multiple warnings and messages throughout the file.
The first error is simply "The 'PercentRelativeLayout' attribute is not declared." This is just the name given to my starting xml tag. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/percentRelativeLayout"
android:background="#000000">
Second, four warnings appear in the AndroidManifest with a similar message: "The 'http://schemas.android.com/apk/res/android:xxxx' attribute is not declared." where 'xxxx' is versionCode, versionName, label, and icon. The manifest file is not very extensive at all:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MyProject.MyProject" android:versionCode="1"
android:versionName="1.0">
<uses-sdk />
<application android:label="MyProject"
android:icon="#drawable/Icon"></application>
</manifest>
On top of all this, there are 4 messages showing that say:
"Could not find schema information for the element 'manifest'."
"Could not find schema information for the attribute 'package'."
"Could not find schema information for the attribute 'uses-sdk'."
"Could not find schema information for the element 'application'."
What does all this mean and how can I get back to actually developing this app?
Figured it out myself, I am not very good at this. The tag must be .
The manifest errors, I don't know, but they seemed to resolve themselves.
The definition is:
<android.support.percent.PercentRelativeLayout>
You need to include the proper package name to this layout or else it will not be found.
As for the AndroidManifest.xml this looks fine from a first glance.

Android and XML

I am new to Android development (just started today). I am familiarising myself with XML which is new to me. I would really appreciate it if people can help me understand this language.
Please see the XML code I am referring to below:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_super"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom|withText" />
</menu>
Questions:
1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?
2) I am not sure what the namespace usage is for. For example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?
3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.
4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.
Questions:
1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?
-- no xml is data tags so there are opening and closing tags and self contained flags like :
will discribe your fridge and if you have multiple dairy products and some veggies in the fridge it will look like this
<Fridge>
<Dairy>
<Milk />
<Cheese />
</Dairy>
<Veggies>
<Carrots />
<Pumpkin />
</Veggies>
</Fridge>
2) I am not sure what the namespace usage is for. For example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?
so the xmlns is xml namespace and they are defined in schemas like a deffinition of what attributes there can be and namespaces combine a bunch of defined attributes like :
<menu xmlns:android ..
android:name=""
android:orderId="5"
/>
the android schema namespace describes all the attributes that android platform knows about and you can then access them but using android: and then the attributes that is known for that menu type
3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.
the XML in android isn't XML that you would use elsewhere android only uses XML to describe how the screens and menus should look like and behave and the best place to learn more about how android uses xml is to look at developer.android.com and try to look at linear layout and learn from there
4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.
the : in "that:this" is use this attribute from that namespace and the namespaces are defined with xmlns:NAMEDITWHATEVER="schema location"
NAMEDITWHATEVER:attribute1="what ever this attribute describes"
Yes, you can think of it as a nested structure, much like the tree of a file system
Yes, it means that menu has two of those attributes. For more information about namespaces, reference this post.
Without knowing what questions W3 didn't help you with, it's hard to tell what it is that you're looking for. XML is very straightforward. There isn't more to it than meets the eye.
The colon in foo:bar means that bar is in the foo namespace.

Overcome resource/.axml difficulties in HelloWorld Xamarin Android app

I am starting out in Xamarin to create an Android app for the first time, so I am following the most basic Xamarin Android tutorial. I get to the point where I am editing my Strings.xml file for my UI controls. I do so, and compile, and get:
C:\...\main.xml(0,0): Error: No resource found that matches the given name (at 'text' with value '#string/hello'). (AndroidHello)
I don't have a main.xml, but I do have a Main.axml, which was apparently generated with the solution. Am I expected to edit this file to match my .cs files? That doesn't seem right at all. Or should it be re-generated from the .cs somehow?
I searched around to try to understand more about .axml files, so I understand that they can be used to specify a layout, instead of doing so in C# code. So I thought I could just delete the .axml file and rely on C# only--but then my Resource.String.whatever resources that I specified in Strings.xml won't work when referenced from my C# code.
Strings.xml.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="helloButtonText">Say Hello</string>
<string name="helloLabelText">Hello Xamarin.Android</string>
</resources>
As mentioned, the .axml file references strings that no longer exist. How should I resolve that?
You probably have the following Button defined in the main.axml file:
<Button
android:id="#+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Hello" />
Replace the #string/Hello and you should be good to go. If you changed the string.xml then "#string/helloButtonText" might be the replacement you need, or simply "Say Hello".

Android custom attributes on "normal" views?

After taking a look at theming for Fede's UberMusic I came across the file album_screen.xml. Below is the source of that file. Basically I noticed that his themes have the ability to use custom views that are a part of his application, and that they have this XML namespace at the top theme. I am missing the connection as to how he is able to apply his attributes to views that he does not control, and how Eclipse will compile the cod below without fail. I placed the URL http://schemas.uberdroidstudio.com/theme into my browser's address bar but nothing came up, and I cannot figure out where/ how Eclipse knows the attributes that the namespace supports. Thank you ahead of time for your help.
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:theme="http://schemas.uberdroidstudio.com/theme">
<TextView
android:id="#id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
theme:textFilter="uppercase" /> <!-- This is the interesting line -->
I suspect that the theme:textFilter="uppercase" line isn't actually having an effect on the (apparently vanilla) TextView.
As for the URL of the namespace, it is interesting that you can't access it, since it does not appear to be a local styleable (Android would have you refer to a local styleable namespace as http://schemas.android.com/apk/res/your.package). +1 for novelty.
The solution is actually not as complicated as I originally thought. XML namespaces are arbitrary strings that just need to be unique. If your namespace does not start with http://schemas.android.com/apk/res then it is not validated and the APK package is not checked for declare-styleable or the like.
Now a custom namespace if very simple to implement, as illustrated by this code snippet in GitHub. Finally, applying custom XML attributes to "normal" widgets can be accomplished by using the LayoutInflater.Factory and calling setFactory before you inflate your views. Throw it all together and you have a highly theme-able, XML driven application like Fede's UberMusic.

Categories

Resources