android获取正在运行的应用程序
2012-12-18 13:59:24 来源:WEB开发网核心提示://类PackageInfo主要包括ApplicationInfo getInfo(String name)方法class PackageInfo { private List<ApplicationInfo> appList; public PackageInfo(Context conte
//类PackageInfo主要包括ApplicationInfo getInfo(String name)方法
class PackageInfo {
private List<ApplicationInfo> appList;
public PackageInfo(Context context){
//get all package data
PackageManager pm = context.getApplicationContext().getPackageManager();
appList = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
}
public ApplicationInfo getInfo(String name){
if(name == null){
return null;
}
for(ApplicationInfo appInfo : appList){
if(name.equals(appInfo.processName)){
return appInfo;
}
}
return null;
}
}
xml文件:
class PackageInfo {
private List<ApplicationInfo> appList;
public PackageInfo(Context context){
//get all package data
PackageManager pm = context.getApplicationContext().getPackageManager();
appList = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
}
public ApplicationInfo getInfo(String name){
if(name == null){
return null;
}
for(ApplicationInfo appInfo : appList){
if(name.equals(appInfo.processName)){
return appInfo;
}
}
return null;
}
}
xml文件:
lsit:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="40dip"
android:layout_height="40dip"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="40dip"
android:layout_height="40dip"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
更多精彩
赞助商链接