国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

如何獲取android手機中已安裝應用信息

發(fā)布時(shí)間:2021-09-27 17:50 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 開(kāi)發(fā)技術(shù)

這篇文章主要介紹了如何獲取android手機中已安裝應用信息,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著(zhù)大家一起了解一下。

直接拿來(lái)就用:

/**
	 * 是否已經(jīng)安裝該應用
	 * @param context
	 * @param apk_package 包名
	 * @return
	 */
	public static boolean isInstallApp(Context context, String apk_package) {
		PackageInfo packageInfo;
		try {
			packageInfo = context.getPackageManager().getPackageInfo(
					apk_package, 0);
		} catch (NameNotFoundException e) {
			packageInfo = null;
			e.printStackTrace();
		}
		if(packageInfo !=null ){
				return true;
		}
		return false;
	}
	
	/**
	 * 遍歷一個(gè)路徑下的文件夾內的指定文件
	 * @param Path 搜索目錄
	 * @param Extension 擴展名(判斷的文件類(lèi)型的后綴名)
	 * @param IsIterative  是否進(jìn)入子文件夾  
	 * @return
	 */
	public static final List<String> GetFiles(String Path, String Extension,boolean IsIterative)  {  
		List<String> apklist = new ArrayList<String>(); // 結果 List   
		try {
			File[] files = new File(Path).listFiles();  
			for (int i = 0; i < files.length; i++) {  
				File f = files[i];  
				if (f.isFile()) {  
					if (f.getPath() .substring(f.getPath().length() - Extension.length()) .equals(Extension)) // 判斷擴展名   
						apklist.add(f.getPath());  
					if (!IsIterative)  
						break;  //如果不進(jìn)入子集目錄則跳出   
				} else if (f.isDirectory() && f.getPath().indexOf("/.") == -1) // 忽略點(diǎn)文件(隱藏文件/文件夾)   
					GetFiles(f.getPath(), Extension, IsIterative);  //這里就開(kāi)始遞歸了   
			}  
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	    return apklist;  
	} 
	
	/**
	 * 根據本地路徑安裝apk
	 * @param apk_url
	 */
	public static void installApkFromLocalPath(Context context,String apk_url){ 
		try {
			Intent intent = new Intent(Intent.ACTION_VIEW); 
			intent.setDataAndType(Uri.fromFile(new File(apk_url)), "application/vnd.android.package-archive"); 
			context.startActivity(intent); 
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	} 
	/**
	 * 卸載應用
	 * @param context
	 * @param apk_pkg 包名
	 */
	public static void unInstallApkFromPackage(Context context,String apk_pkg){ 
		try {
			Intent intent = new Intent(Intent.ACTION_DELETE); 
			intent.setData(Uri.parse("package:"+apk_pkg));
			context.startActivity(intent); 
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	} 
	/**
	 * 根據包名打開(kāi)另外一個(gè)應用
	 * @param context
	 * @param apk_pkg 包名
	 */
	public static void openApkFromPackage(Context context,String apk_pkg){ 
		try {
			Intent intent = new Intent(Intent.ACTION_VIEW);   
		    intent.setComponent(new ComponentName(context, apk_pkg));   
		    context.startActivity(intent);  
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	} 	

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

少妇极品熟妇人妻| 亚洲av色影在线| 国产精品嫩草影院一二三区入口| 亚洲精品97久久中文字幕无码| 天堂网www在线资源网| 国产精品99久久久久久宅男小说|