List<ApplicationInfo>infos = packManager.getInstalledApplications(PackageManager.GET_ACTIVITIES)
//获取到安装的App列桥晌唤表
Log.i("app", infos.size()+"")
for(ApplicationInfo info: infos){
Log.i("app", "appName--->"+packManager.getApplicationLabel(info)+""敏凯)
try {
PackageInfo packInfo = packManager.getPackageInfo(info.packageName, PackageManager.GET_PERMISSIONS)
String permissons [] = packInfo.requestedPermissions
//获取该app的所有权限
int length = permissons.length
for(int i = 0 i <length i ++){
Log.i("app",permissons[i])
}
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace()
}
}
以上是获取系统安装程序列表和对应的权限的方法谨扒,知道这些就可以做出来了
android这边提供了相应的接口。[java] view plain copy
final PackageManager packageManager = getActivity().getPackageManager()//获取packagemanager
List<PackageInfo>pinfo = packageManager.getInstalledPackages(0)//获取所有已安装程序的包信息
if(pinfo != null){
for(int i = 0i <pinfo.size()i++){
String packName = pinfo.get(i).packageName
Log.d("info", "-->"+packName)
}
}
上面的例子可以打印出安装软件的包名。每个猛腔程序的包名在android手机里都是唯一的。
判断手机是否安装了某个程序,如果安装了此程序,删除它。
[java] view plain copy
private void uninstallSoftware(Context context, String name) {
final PackageManager packageManager = context.getPackageManager()
try {
PackageInfo pInfo = packageManager.getPackageInfo(name,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
if(pInfo!=null){
//删除盯岁软件
Uri uri = Uri.parse("package:"+ name)
Intent intent = new Intent(Intent.ACTION_DELETE, uri)
context.startActivity(intent)
}
} catch (NameNotFoundException e) {
e.printStackTrace()
}
}
从android2.2开始软件可以安装到SD卡枝则衫上,所以也有相应接口判断程序是否安装到SD卡上
[java] view plain copy
private void isInstallOnSd(Context context,String name){
PackageManager pm=context.getPackageManager()
ApplicationInfo appInfo
try {
appInfo = pm.getApplicationInfo(name, 0)
if ((appInfo.flags &ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
// App on sdcard
Log.d("info", "app on sd")
}
} catch (NameNotFoundException e) {
e.printStackTrace()
}
}
1.下载软件安装包,存放在手机的SD卡上,这样就可以在Android手机里直接察握安装。这个方法需要首先对手机进行设置,“菜单键”-settings(设置)-Applications(应用程序)-Unknown sources(选择“未知源”)2.可以用USB数据线连接电脑,然后在电脑上对Android手机进行安装,但是首先需要在电脑上安装APK安装器等软件,可以批量安装程序,非常方便。枯没薯这个方没者法也需要首先对手机进行设置,settings(设置)-Applications(应用程序)-Development(开发)-USB debugging(选择“USB 调试”)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)