Ver Fonte

add TAndroidHelperEx.GetPackageLabel

KngStr há 3 anos atrás
pai
commit
89742a4547
1 ficheiros alterados com 28 adições e 2 exclusões
  1. 28 2
      Source/ksAndroid.Helpers.pas

+ 28 - 2
Source/ksAndroid.Helpers.pas

@@ -143,6 +143,8 @@ type
 
     /// <summary>Returns Application package name</summary>
     class function GetPackageName: string; static;
+    /// <summary>Returns Application package label</summary>
+    class function GetPackageLabel: string; static;
     /// <summary>Returns MimeType from filename</summary>
     class function GetMimeType(AFileName: string): JString; static;
     /// <summary>Returns Primary SDCard path</summary>
@@ -470,6 +472,23 @@ begin
     Result := Result.trim();
 end;
 
+class function TAndroidHelperEx.GetPackageLabel: string;
+var
+  LApplicationInfo: JApplicationInfo;
+  LLabel: JCharSequence;
+begin
+  Result := '';
+  try
+    LApplicationInfo := Context.getPackageManager.getApplicationInfo(Context.getPackageName, 0);
+    if LApplicationInfo <> nil then begin
+      LLabel := Context.getPackageManager.getApplicationLabel(LApplicationInfo);
+      if LLabel <> nil then
+        Result := JCharSequenceToStr(LLabel);
+    end;
+  except
+  end;
+end;
+
 class function TAndroidHelperEx.GetPackageName: string;
 begin
   Result := JStringToString(Context.getPackageName);
@@ -490,8 +509,15 @@ class function TAndroidHelperEx.GetTargetSdkVersion: Integer;
 var
   LApplicationInfo: JApplicationInfo;
 begin
-  LApplicationInfo := Context.getPackageManager.getApplicationInfo(Context.getPackageName, 0);
-  Result := LApplicationInfo.targetSdkVersion;
+  try
+    LApplicationInfo := Context.getPackageManager.getApplicationInfo(Context.getPackageName, 0);
+    if LApplicationInfo <> nil then
+      Result := LApplicationInfo.targetSdkVersion
+    else
+      Result := -1;
+  except
+    Result := -1;
+  end;
 end;
 
 class function TAndroidHelperEx.HasAssocApp(const Intent: JIntent): Boolean;