/**
* 判断该应用在手机中的安装情况
* @param PackageManager pm ,String packageName int ,versionCode
* @param packageName 要判断应用的包名
* @param versionCode 要判断应用的版本号
*/
private int doType(PackageManager pm, String packageName, int versionCode)
{
List<PackageInfo> pakageinfos = pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo pi : pakageinfos)
{
String pi_packageName = pi.packageName;
int pi_versionCode = pi.versionCode;
//如果这个包名在系统已经安装过的应用中存在
if (packageName.endsWith(pi_packageName))
{
//Log.i("test","此应用安装过了");
if (versionCode == pi_versionCode)
{
CommonUtil.log(packageName+"已经安装,不用更新,可以卸载该应用");
return INSTALLED;
}
else if (versionCode > pi_versionCode)
{
CommonUtil.log(packageName+"已经安装,有更新");
return INSTALLED_UPDATE;
}
}
}
CommonUtil.log("未安装该应用,可以安装");
return UNINSTALLED;
}
public static Intent openFile(String filePath)
{
File file = new File(filePath);
if (!file.exists())
return null;
/* 取得扩展名 */
String end = file.getName()
.substring(file.getName().lastIndexOf(".") + 1,
file.getName().length())
.toLowerCase();
/* 依扩展名的类型决定MimeType */
if (end.equals("m4a") || end.equals("mp3") || end.equals("mid")
|| end.equals("xmf") || end.equals("ogg") || end.equals("wav"))
{
return getAudioFileIntent(filePath);
}
else if (end.equals("3gp") || end.equals("mp4"))
{
return getAudioFileIntent(filePath);
}
else if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp"))
{
return getImageFileIntent(filePath);
}
else if (end.equals("apk"))
{
return getApkFileIntent(filePath);
}
else if (end.equals("ppt"))
{
return getPptFileIntent(filePath);
}
else if (end.equals("xls"))
{
return getExcelFileIntent(filePath);
}
else if (end.equals("doc"))
{
return getWordFileIntent(filePath);
}
else if (end.equals("pdf"))
{
return getPdfFileIntent(filePath);
}
else if (end.equals("chm"))
{
return getChmFileIntent(filePath);
}
else if (end.equals("txt"))
{
return getTextFileIntent(filePath, false);
}
else
{
return getAllIntent(filePath);
}
}
//Android获取一个用于打开APK文件的intent
public static Intent getAllIntent(String param)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "*/*");
return intent;
}