Sunday, November 27, 2011

Access the features of Android device


To access the available features in an Android device, the code snippet,


PackageManager mPackageManager = getPackageManager();
FeatureInfo[] systemFeature = mPackageManager
.getSystemAvailableFeatures();
for (int i = 0; i < systemFeature.length; i++) {
String feature = systemFeature[i].name;
if (feature == null) {
feature = "OpenGL Version : " + systemFeature[i].reqGlEsVersion;
}
systemFeaturesList.add(feature);
}


I just list it into a list, the complete code is,


public class FeaturesListActivity extends Activity {

private final String TAG = "FeaturesListActivity";
private ListView mList;
private ArrayList systemFeaturesList = new ArrayList();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mList = (ListView) findViewById(R.id.list);
PackageManager mPackageManager = getPackageManager();
FeatureInfo[] systemFeature = mPackageManager
.getSystemAvailableFeatures();
for (int i = 0; i < systemFeature.length; i++) {
String feature = systemFeature[i].name;
if (feature == null) {
feature = "OpenGL Version : " + systemFeature[i].reqGlEsVersion;
}
systemFeaturesList.add(feature);
Log.i(TAG, "**************** System Feature = " + feature);
}
mList.setAdapter(new SystemFeatureListAdapter(this));
}

private class SystemFeatureListAdapter extends BaseAdapter {

private Context mContext;

public SystemFeatureListAdapter(Context context) {
mContext = context;
}

@Override
public int getCount() {
return systemFeaturesList.size();
}

@Override
public Object getItem(int index) {
return systemFeaturesList.get(index);
}

@Override
public long getItemId(int id) {
return id;
}

@Override
public View getView(int position, View view, ViewGroup parent) {
TextView text = new TextView(mContext);
text.setText(systemFeaturesList.get(position));
return text;
}
}
}


The screen-shot of the application is,

No comments:

Post a Comment

Androidians