Menu

170818Ago - CHAPTER 3

~~~**170818Ago - CHAPTER 3**

Last day we recovery the device information to show it in a TextView.

Calling to getSystemAvailableFeatures() method of a instance of PackageManager, but this give us more information than we need.

Perhaps we prefer get only the capabilities that we are searching calling to hasSystemFeature(String name) instead.

PackageManager has defined constants for this names, I go to change MySystemInfo class to do this:

package homebrew.dhtejada.androidblog.mysuperapp;
import android.content.Context;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import android.widget.TextView;

import java.util.ArrayList;

public class MySystemInfo {
private static final String TAG = "MySystemInfo";
Context context;
ArrayList<String> report=null;
String[][] fNames={
{"Audio", PackageManager.FEATURE_AUDIO_OUTPUT},
{"Audio-pro",PackageManager.FEATURE_AUDIO_PRO},
{"Bluetooth",PackageManager.FEATURE_BLUETOOTH},
{"Camera",PackageManager.FEATURE_CAMERA},
{"Camera-front",PackageManager.FEATURE_CAMERA_FRONT},
{"Autofocus",PackageManager.FEATURE_CAMERA_AUTOFOCUS},
{"Flash",PackageManager.FEATURE_CAMERA_FLASH},
{"Finger print",PackageManager.FEATURE_FINGERPRINT},
{"Gamepad",PackageManager.FEATURE_GAMEPAD},
{"GPS",PackageManager.FEATURE_LOCATION_GPS},
{"Microphone",PackageManager.FEATURE_MICROPHONE},
{"MIDI",PackageManager.FEATURE_MIDI},
{"OpenGL Extension",PackageManager.FEATURE_OPENGLES_EXTENSION_PACK},
{"Accelerometer",PackageManager.FEATURE_SENSOR_ACCELEROMETER},
{"Termometer",PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE},
{"Barometer",PackageManager.FEATURE_SENSOR_BAROMETER},
{"Compass",PackageManager.FEATURE_SENSOR_COMPASS},
{"Gyroscope",PackageManager.FEATURE_SENSOR_GYROSCOPE},
{"Telephony",PackageManager.FEATURE_TELEPHONY},
{"Multitouch",PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH},
{"USB Accessory",PackageManager.FEATURE_USB_ACCESSORY},
{"USB Host",PackageManager.FEATURE_USB_HOST},
{"VR Mode",PackageManager.FEATURE_VR_MODE},
{"Webview",PackageManager.FEATURE_WEBVIEW},
{"WIFI",PackageManager.FEATURE_WIFI}
};
String[][] bNames={
{"Board", Build.BOARD},
{"Brand", Build.BRAND},
{"Device", Build.DEVICE},
{"Display", Build.DISPLAY},
{"Fingerprint", Build.FINGERPRINT},
{"Hardware", Build.HARDWARE},
{"Host", Build.HOST},
{"Id", Build.ID},
{"Manufacturer", Build.MANUFACTURER},
{"Model", Build.MODEL},
{"Product", Build.PRODUCT},
{"Manufacturer", Build.MANUFACTURER},
//{"32b ABIs:", Build.SUPPORTED_32_BIT_ABIS.toString()},
//{"64b ABIs", Build.SUPPORTED_64_BIT_ABIS.toString()},
{"Radio", Build.getRadioVersion()},
{"Tags", Build.TAGS},
{"time", Long.toString(Build.TIME)},
{"Build type", Build.TYPE},
{"User", Build.USER}
};
MySystemInfo(Context context){
this.context=context;
report=new ArrayList<String>();
}

@Deprecated
MySystemInfo checkCapabilities(){
    PackageManager pm = context.getPackageManager();
    report.add("");
    FeatureInfo[] features=pm.getSystemAvailableFeatures();
    for (FeatureInfo fi : features){
        report.add(fi.name);
    }
    return this;
}

MySystemInfo customCapabilities(){
    PackageManager pm = context.getPackageManager();
    report.add("");
    report.add("Features in device:");
    for (String[] pair : fNames){
        Log.v(TAG, "FEATURE-> "+pair[0]+" - "+ pair[1]);
        if ((pair[0]!=null) && (pair[1]!=null))
            report.add(pair[0]+": "+ (pm.hasSystemFeature(pair[1])?"Yes" : "No") );
    }
    return this;
}
MySystemInfo addBuidInfo(){
    report.add("Build information:");
    for (String[] pair : bNames){
        Log.v(TAG, "BUILD INFO-> "+pair[0]+" - "+ pair[1]);
        if ((pair[0]!=null) && (pair[1]!=null))
            report.add(pair[0]+": "+ pair[1]);
    }
    return this;
}
MySystemInfo printReport(TextView tv){
    if (report==null) return this;
    String r=new String();
    for (String s:report)
        r+=s+"\n";
    tv.setText(r);
    return this;
}

}
~~~

As you can see I used the Log class to output debug lines in the log. You can see this output in the IDE if you launch the app from ADB Run in connected device. But not if you starts the app from the phone.

Posted by David Hernandez Tejada 2017-08-24 Labels: ANDROID STUDIO ANDROID DEVELOPMENT PROGRAMMING

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.