在PackageManager類中, 每個這些ID也有一個相應的Java-語言的常數, 可以在運行時使查詢是否支持這些功能.
getSystemAvailableFeatures()方法可獲取在系統上功能的列表.
但是,這個程序在模擬器運行時, 總是只可以找到"android.harware.camera"和"android.harware.camera.autofocus". 筆者也不清楚! 希望各位能指出原因, Thx:)
/res/layout/featurelist.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowtext"
android:layout_width="fill_parent"
android:layout_height="40px"
android:textSize="15sp" />
/res/layout/main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No Data" />
</LinearLayout>
AndroidFeatureList.java
package com.AndroidFeatureList;
import android.app.ListActivity;
import android.content.pm.FeatureInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class AndroidFeatureList extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FeatureInfo[] myFeatureInfo = getPackageManager().getSystemAvailableFeatures();
ArrayAdapter<FeatureInfo> itemList = new ArrayAdapter<FeatureInfo>(this, R.layout.featurelist, myFeatureInfo);
setListAdapter(itemList);
}
}
相關文章: 獲取已安裝軟件包(InstalledPackages)及其活動(Activity)的信息
沒有留言:
發佈留言