获取已安装的程序的信息(名称、包名、图标等)
获取未安装的APK文件的信息
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");
}
}
private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");
}
}
private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
获取未安装的APK文件的信息
简单的小问题,如果列出了所有安装的程序,怎么样打开该程序呢?
要调用该程序,有两个必要因素:packageName, className
比如打开计算器程序:
前面是packageName,后面是className,我们尝试取出此两个值即可。
要调用该程序,有两个必要因素:packageName, className
比如打开计算器程序:
Intent i = new Intent();
i.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(i);
i.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(i);
前面是packageName,后面是className,我们尝试取出此两个值即可。
List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
//p.packageName;
//p.activities[0].name; //(className)
}
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
//p.packageName;
//p.activities[0].name; //(className)
}
备忘
.test{
width:200px;
height:50px;
border:1px solid red;
padding:10px;
overflow:hidden; /*不显示超过对象宽度的内容*/
text-overflow:ellipsis; /*当对象内文本溢出时显示省略标记(...)*/
white-space:nowrap; /*限制在一行内显示所有文本*/
}
width:200px;
height:50px;
border:1px solid red;
padding:10px;
overflow:hidden; /*不显示超过对象宽度的内容*/
text-overflow:ellipsis; /*当对象内文本溢出时显示省略标记(...)*/
white-space:nowrap; /*限制在一行内显示所有文本*/
}
IIS就是一个灾难,可操作性很差,不悦。。
IIS默认是允许200k的上传,要上传更大,就得修改IIS的配置文件了。
1 打开IIS的属性,允许直接编辑配置数据库,这样不用停止IIS,否则编辑不了配置文件
2 打开 C:\Windows\System32\Inetsrv\metabase.XML
3 修改 ASPMaxRequestEntityAllowed 里的值,比如1024000,10M的大小
4 保存即可
引用
Request 对象 错误 'ASP 0104 : 80004005'不允许操作 /up/upload.asp,行 20
IIS默认是允许200k的上传,要上传更大,就得修改IIS的配置文件了。
1 打开IIS的属性,允许直接编辑配置数据库,这样不用停止IIS,否则编辑不了配置文件
2 打开 C:\Windows\System32\Inetsrv\metabase.XML
3 修改 ASPMaxRequestEntityAllowed 里的值,比如1024000,10M的大小
4 保存即可
简单的代码,测试至少是可行
public static void downloadFile(String url, String newPath) {
URL myFileUrl = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
Log.e("test", "MalformedURLException: "+e.toString() );
}
try {
HttpURLConnection conn;
conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
FileOutputStream newfile = new FileOutputStream("/sdcard/tmp.apk");
byte[] buffer = new byte[1444];
int byteread = 0;
while ( (byteread = is.read(buffer)) != -1) {
newfile.write(buffer, 0, byteread);
}
is.close();
} catch (Exception e) {
Log.e("test", "returnNetworkBitMap: "+e.toString() );
}finally{
}
}
URL myFileUrl = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
Log.e("test", "MalformedURLException: "+e.toString() );
}
try {
HttpURLConnection conn;
conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
FileOutputStream newfile = new FileOutputStream("/sdcard/tmp.apk");
byte[] buffer = new byte[1444];
int byteread = 0;
while ( (byteread = is.read(buffer)) != -1) {
newfile.write(buffer, 0, byteread);
}
is.close();
} catch (Exception e) {
Log.e("test", "returnNetworkBitMap: "+e.toString() );
}finally{
}
}
安装某个apk文件:
注:如果文件不存在会提示解析出错
卸载某个程序:
参考阅读:
Install and Uninstall Android applications with PackageInstaller,包含判断是否开启安装第三方程序的支持
另外还有 Android Intent的几种用法全面总结,必要的时候可以参考啦
String fileName = "/sdcard/tmp.apk";
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(fileName) ), "application/vnd.android.package-archive");
startActivity(i);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(fileName) ), "application/vnd.android.package-archive");
startActivity(i);
注:如果文件不存在会提示解析出错
卸载某个程序:
Uri packageURI = Uri.parse("package:com.aslibra.test");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
参考阅读:
Install and Uninstall Android applications with PackageInstaller,包含判断是否开启安装第三方程序的支持
另外还有 Android Intent的几种用法全面总结,必要的时候可以参考啦






