Showing posts with label Android code sample: general info. Show all posts
Showing posts with label Android code sample: general info. Show all posts

cat /system/etc/permissions/handheld_core_hardware.xml on your Android device

This example simple display the file /system/etc/permissions/handheld_core_hardware.xml on my Android device.

handheld_core_hardware.xml of HTC One X
For what:
In my old post "List attached USB devices in USB Host mode", Anonymous commented have to check the xml file "/system/etc/permissions/handheld_core_hardware.xml" for < feature name="android.hardware.usb.host" />. Coincidentally I have a post to "Run Linux command with ProcessBuilder", so I modify it to display the content of "/system/etc/permissions/handheld_core_hardware.xml" using Linux command "cat".

package com.example.androidruncommand;

import java.io.IOException;
import java.io.InputStream;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView textCommand, textReturn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textCommand = (TextView) findViewById(R.id.textcommand);
textReturn = (TextView) findViewById(R.id.textreturn);

String[] command = { "cat", "/system/etc/permissions/handheld_core_hardware.xml" };
StringBuilder cmdReturn = new StringBuilder();

String stringCommand = "$ ";
for(int i=0; i<command.length; i++){
stringCommand += command[i] + " ";
}
textCommand.setText(stringCommand);

try {
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();

InputStream inputStream = process.getInputStream();
int c;
while ((c = inputStream.read()) != -1) {
cmdReturn.append((char) c);
}

textReturn.setText(cmdReturn.toString());

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://arteluzevida.blogspot.com/"
android:textStyle="bold" />

<TextView
android:id="@+id/textcommand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/textreturn"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

</LinearLayout>

Or, you can pull the file from your device using DDMS of Android Development Tools.

/system/etc/permissions/handheld_core_hardware.xml in HTC One X
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- These are the hardware components that all handheld devices
must include. Devices with optional hardware must also include extra
hardware files, per the comments below.

Handheld devices include phones, mobile Internet devices (MIDs),
Personal Media Players (PMPs), small tablets (7" or less), and similar
devices.
-->
<permissions>
<feature name="android.hardware.camera" />
<feature name="android.hardware.location" />
<feature name="android.hardware.location.network" />
<feature name="android.hardware.sensor.compass" />
<feature name="android.hardware.sensor.accelerometer" />
<feature name="android.hardware.bluetooth" />
<feature name="android.hardware.touchscreen" />
<feature name="android.hardware.microphone" />
<feature name="android.hardware.screen.portrait" />
<feature name="android.hardware.screen.landscape" />
<!-- devices with GPS must include android.hardware.location.gps.xml -->
<!-- devices with an autofocus camera and/or flash must include either
android.hardware.camera.autofocus.xml or
android.hardware.camera.autofocus-flash.xml -->
<!-- devices with a front facing camera must include
android.hardware.camera.front.xml -->
<!-- devices with WiFi must also include android.hardware.wifi.xml -->
<!-- devices that support multitouch must include the most appropriate one
of these files:

If only partial (non-independent) pointers are supported:
android.hardware.touchscreen.multitouch.xml

If up to 4 independently tracked pointers are supported:
include android.hardware.touchscreen.multitouch.distinct.xml

If 5 or more independently tracked pointers are supported:
include android.hardware.touchscreen.multitouch.jazzhand.xml

ONLY ONE of the above should be included. -->
<!-- devices with an ambient light sensor must also include
android.hardware.sensor.light.xml -->
<!-- devices with a proximity sensor must also include
android.hardware.sensor.proximity.xml -->
<!-- GSM phones must also include android.hardware.telephony.gsm.xml -->
<!-- CDMA phones must also include android.hardware.telephony.cdma.xml -->
<!-- Devices that have low-latency audio stacks suitable for apps like
VoIP may include android.hardware.audio.low_latency.xml. ONLY apps
that meet the requirements specified in the CDD may include this. -->
</permissions>

But...I can't find < feature name="android.hardware.usb.host" /> in my handheld_core_hardware.xml. But it support USB Host mode actually.

Get the Android version of device

The static final int Build.VERSION.SDK_INT store user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES.

This exercise use Android's SparseArrays to store SDK_INT-Build.VERSION_CODES pairs. SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.


Get the Android version of device
Get the Android version of device

package com.example.androidversion;

import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.util.SparseArray;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

static SparseArray<String> arrayVC = new SparseArray<String>();
static {
arrayVC.append(VERSION_CODES.BASE, "The original, first, version of Android.");
arrayVC.append(VERSION_CODES.BASE_1_1, "First Android update, officially called 1.1");
arrayVC.append(VERSION_CODES.CUPCAKE, "Android 1.5");
arrayVC.append(VERSION_CODES.CUR_DEVELOPMENT, "Magic version number...");
arrayVC.append(VERSION_CODES.DONUT, "Android 1.6");
arrayVC.append(VERSION_CODES.ECLAIR, "Android 2.0");
arrayVC.append(VERSION_CODES.ECLAIR_0_1, "Android 2.0.1");
arrayVC.append(VERSION_CODES.ECLAIR_MR1, "Android 2.1");
arrayVC.append(VERSION_CODES.FROYO, "Android 2.2");
arrayVC.append(VERSION_CODES.GINGERBREAD,"Android 2.3");
arrayVC.append(VERSION_CODES.GINGERBREAD_MR1, "Android 2.3.3");
arrayVC.append(VERSION_CODES.HONEYCOMB, "Android 3.0");
arrayVC.append(VERSION_CODES.HONEYCOMB_MR1, "Android 3.1");
arrayVC.append(VERSION_CODES.HONEYCOMB_MR2, "Android 3.2");
arrayVC.append(VERSION_CODES.ICE_CREAM_SANDWICH,"Android 4.0");
arrayVC.append(VERSION_CODES.ICE_CREAM_SANDWICH_MR1,"Android 4.0.3");
arrayVC.append(VERSION_CODES.JELLY_BEAN, "Android 4.1");
arrayVC.append(VERSION_CODES.JELLY_BEAN_MR1, "Android 4.2");
arrayVC.append(VERSION_CODES.JELLY_BEAN_MR2, "Android 4.3");
arrayVC.append(VERSION_CODES.KITKAT, "Android 4.4");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);

TextView textView = new TextView(this);
setContentView(textView);

int version = Build.VERSION.SDK_INT;
String BuildVersion = arrayVC.get(version, "unknown");

textView.setText(BuildVersion);
}

}