Access long key from meta-data from AndroidManifeast.xml - android

I implemented the following code and want to access the key meta-data value as a Long integer from the MetaActivity.java class.
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slk.metachecking"
android:versionCode="1"
android:versionName="1.0" >
<application>
<meta-data android:name="key" android:value="488659867867350" />
</application>
MetaActivity.java
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),
PackageManager.GET_META_DATA);
Bundle metaData = ai.metaData;
metaData.getString("key"); // Returns -36235050
metaData.getLong("key"); // Returns 0
Does Android support long as a type in meta-data tag?

refer to http://developer.android.com/guide/topics/manifest/meta-data-element.html, as you can see only getInt is supported, so if you want to specify long value set it as a string (for example L123456789123456789) and parse it as a substring(1)

Related

getRootInActiveWindow() giving null value

private void click() {
Log.d(TAG, String.format("Click [%d, %d]", cursorLayout.x, cursorLayout.y));
- AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) return;
AccessibilityNodeInfo nearestNodeToMouse = findSmallestNodeAtPoint(nodeInfo, cursorLayout.x, cursorLayout.y + 50);
if (nearestNodeToMouse != null) {
logNodeHierachy(nearestNodeToMouse, 0);
nearestNodeToMouse.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
nodeInfo.recycle();
}
I am using AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); i am getting null value here
I try
view.createAccessibilityNodeInfo();
By these method i got node. but I got one error seald unreachable like that.
view.getRootView().createAccessibilityNodeInfo();
xml file for accesibility
ManifestFile
From the comments I can't seem to get you to show the contents of your service config... I don't want to confuse you with mine, but I feel this example may be more productive.
In your manifest, you'll need to have an accessibility_service_config file referenced. The name is not important.
<service
android:name="..."
android:enabled="true"
android:label="..."
android:description="..."
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
Then res/xml/accessibility_service_config.xml needs to be something along the lines of
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:accessibilityEventTypes="typeAllMask"
android:canPerformGestures="false"
android:canRetrieveWindowContent="true"
android:description="..."
/>
It could be that you just need to set canRetrieveWindowContent to true. Documentation:
Attribute whether the accessibility service wants to be able to retrieve the active window content. This setting cannot be changed at runtime.
Required to allow setting the #AccessibilityServiceInfo#FLAG_RETRIEVE_INTERACTIVE_WINDOWS flag.
May be a boolean value, such as "true" or "false".
Or it could be the contents of needs at least android:accessibilityFlags="flagReportViewIds"
According to the documentation:
This flag requests that the AccessibilityNodeInfos obtained by an AccessibilityService contain the id of the source view. The source view id will be a fully qualified resource name of the form "package:id/name", for example "foo.bar:id/my_list", and it is useful for UI test automation. This flag is not set by default.
I strongly recommend you configure your service properly - I don't recommend copying and pasting my service config verbatim.
Your service config XML is malformed:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"> <-- the angle bracket shouldn't be here -->
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:canPerformGestures="true"
android:canRetrieveWindowContent="true"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="200"
android:packageNames="com.example.accesibility"
android:canRequestEnhancedWebAccessibility="true"
</accessibility-service>
change it to:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:canPerformGestures="true"
android:canRetrieveWindowContent="true"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="200"
android:packageNames="com.example.accesibility"
android:canRequestEnhancedWebAccessibility="true"> <-- the angle bracket should be here -->
</accessibility-service>

Launcher icon Xamarin Android not found

I'm doing a Hello World in Xamarin Android, but when I try to change the launcher icon, it throws the following error: "No resource found that matches the given name (at 'icon' with value '#drawable/icon')."
Actually I don't have any "icon" in my resources, the icons' names are ic_launcher:
And my manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="HelloWorldXamarinAndroid.HelloWorldXamarinAndroid" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="Hi android" android:icon="#drawable/ic_launcher"></application>
</manifest>
I've already cleaned the project and tried to rebuild it, can someone help me?
If I change all the images' names to "Icon.png" and the manifest with "#drawable/Icon", it works, my question is, why Xamarin doesn't work with other names
I found the problem, in Main Activity is set the icon too, so it's necessary to set the new name there too:
[Activity(Label = "HelloWorldXamarinAndroid", MainLauncher = true, Icon = "#drawable/ic_launcher")]
public class MainActivity : Activity
{
...
}
Right click the Droid project and select Android Manifest from the menu list. Under Application Icon you will see which icon the application is referencing.
Below is a picture of where the icon is being references.

parsing an android manifest file with JDOM2

hope you're fine.
I have to parse an android manifest file to extract data like 'the minSdkVersion' used, after several seraches I found a code using JDOM.
Display data related to "uses-sdk" was expected but When running I got a null object.
Need Help
Thanks
Manifest Example
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.rssfeed"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
The code
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
public class ManifestP2 {
static Document document;
static Element root;
static NeededTag tags;//Data receiver
public static void main(String[] args){
SAXBuilder builder = new SAXBuilder();
try{
document = builder.build(new File("AndroidManifest.xml"));
}catch(Exception e){
System.out.println(e.getMessage());
}
root = document.getRootElement();
tags = new NeededTag();
findTag();
System.out.println(tags.usesSdk.toString());
}
static void findTag(){
//get values for "uses-sdk" tag
Element sdk = root.getChild("uses-sdk");
tags.usesSdk.minSdk = sdk.getAttributeValue("android:minSdkVersion");
tags.usesSdk.targetSdk = sdk.getAttributeValue("android:targetSdkVersion");
}
}
The attributes in your document are in the android namespace. Namespaces in XML add a level of complexity, that's true, but they also ensure that you can have special types of documents, like your manifest, where you can store "meta" types of information inside the same document as regular data, while still guaranteeing that there won't be any name collisions.
That's a complicated way of saying that where you see android in your XML document, it refers to a namespace, not the attribute name.
So, for example, where you have:
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
that really means you have your own element uses-sdk and that element has 2 attributes, one called minSdkVersion, and the other called targetSdkVersion. Those attributes are in the namespace with the URI: http://schemas.android.com/apk/res/android.
To get those attributes off the element in JDOM, you have to ask for them by name, and in the right namespace.
To do that, you have the code:
Namespace ans = Namespace.getNamespace("android", "http://schemas.android.com/apk/res/android");
String min = sdk.getAttributeValue("minSdkVersion", ans);
String target = sdk.getAttributeValue("targetSdkVersion", ans);
You declare the namespace to search for (only the URI is important when searching, the android namespace prefix is there for convenience only)

The Client Token must be specified in the string resource file as com.facebook.accountkit.ClientToken

I have an android project and i want to use facebook account kit. I did all settings but when i run the project, i am getting this message;
E/AndroidRuntime: 500: Initialization error: 503: The Client Token must be specified in the string resource file as com.facebook.accountkit.ClientToken
But i specified it in strings.xml
<string name="ACCOUNT_KIT_CLIENT_TOKEN">***</string>
AndroidManifest.xml
<meta-data android:name="com.facebook.accountkit.ClientToken"
android:value="#string/ACCOUNT_KIT_CLIENT_TOKEN" />
Waiting for your helps, thank you.
For me solution was adding following to the manifest file:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.accountkit.ApplicationName"
android:value="#string/app_name"/>
<meta-data
android:name="com.facebook.accountkit.ClientToken"
android:value="#string/ACCOUNT_KIT_CLIENT_TOKEN" />
And the creating the respective String resources as:
facebook_app_id with app id, found at top-left corner next to navigation pane of facebook developer console for your app.
app_name which is already defined generally in your string resource file with the name of your app.
ACCOUNT_KIT_CLIENT_TOKEN with value found at Settings>advanced in navigation drawer of facebook developer console. Then go to Security, there you will find "Client Token". Use this client token value for value of this String resource.
This worked for me. Hope this helps.
You should have something like this in string resources (you have to get the app_id)
<string name="facebook_app_id">2077942129****</string>
and in you Manifest:
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
Check the attached to find to solution click on your products then go account-kit-->settings

Multiple API keys in the same Android project

Is it possible to specify multiple keys for Google Maps Android API in the same code base?
It looks like I have to change the key in manifest file each time I change keystore. It's not very convenient, imho, if you need to test the app signed with keys form debug and release keystores.
I added both keys in the manifest at once. Like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
..
android:versionCode="1"
android:versionName="1.0" >
<!-- RELEASE key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-release-keu" />
<!-- DEBUG key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-debug-key" />
</application>
</manifest>
Apparently, this works. Looks like Google code is smart enough to use relevant key automatically.
I don't think this is what you want to do. You should add both debug and release SHA1 key to API key on Google Developer API Console. Take a look at this answer
AFAIK, there is no programmatical form on doing this. For comodity, you can define API keys in strings.xml, and retrieve it from the manifest
String debugMapKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String releaseMapKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String mapKey = BuildConfig.DEBUG ? debugMapKey : releaseMapKey;
MapView mv = new MapView(this, mapKey);

Categories

Resources