标签:except pes 一个 result man name pre func android
有个需求,想判断手机里是否安装指定的app,没找到现成的代码,参考Delphi代码实现了一个,当返回空串时,表示没有安装app。
function GetVersionString(APackageName:string): string; //uses Androidapi.JNI.GraphicsContentViewText,Androidapi.Helpers,androidapi.jni.javatypes; var PackageInfo: JPackageInfo; PackageManager: JPackageManager; AppContext: JContext; begin AppContext := TAndroidHelper.Context; if AppContext <> nil then begin PackageManager := AppContext.getPackageManager; if PackageManager <> nil then begin try PackageInfo := AppContext.getPackageManager.getPackageInfo(StringToJString(APackageName), 0); except Exit(string.Empty); end; if PackageInfo <> nil then Exit(JStringToString(PackageInfo.versionName)); end; end; Result := string.Empty; end;
标签:except pes 一个 result man name pre func android
原文地址:https://www.cnblogs.com/kinglandsoft/p/12389276.html