2

J'utilise Delphi 10 seattle pour le développement de l'application mobile Android et j'ai l'obligation d'obtenir l'Id de l'email de l'appareil. Pour cela, j'ai essayé d'utiliser l'exemple suivant: for getting EMail address of Mobile. Mais quand j'ai essayé les interfaces (JAccountClass, JAccount, JAccountManagerClass), je demande à d'autres interfaces - JActivity, JAccountManagerCallback et JAccountManagerFuture. Aidez-moi s'il vous plaît à trouver ces classes de dépendance. Et où puis-je obtenir ces fichiers.Obtenir l'adresse email du périphérique dans Android en utilisant Firemonkey

Merci à l'avance

+1

Essayer le [androïde-objet-pascal-wrapper] de dépôt (https://github.com/FMXExpress/android-object-pascal-wrapper). (Vérifiez ces [android.accounts.AccountManager] (https://github.com/FMXExpress/android-object-pascal-wrapper/blob/5f21605bd45a1947f8de2cf37c2f2c5ee239197a/android-23/android.accounts.AccountManager.pas), [android.accounts .AccountManagerFuture] (https://github.com/FMXExpress/android-object-pascal-wrapper/blob/5f21605bd45a1947f8de2cf37c2f2c5ee239197a/android-23/android.accounts.AccountManagerFuture.pas)) – RRUZ

+0

J'ai ajouté les fichiers ci-dessus, puis lors de la compilation Je reçois erreur ce fichier introuvable - android.accounts.AccountManagerFuture, android.accounts.AccountManagerCallback, android.app.Activity, android.content.ClipData. Donc, si j'ajoute ces fichiers, alors cela demande plus de fichiers de dépendance et si je définis le chemin de recherche du dossier, alors je reçois aussi un message d'erreur circulaire. S'il vous plaît aider à résoudre ce problème de dépendance. – test12345

+0

Toute idée comment compiler cette unité – test12345

Répondre

0

Pour éviter les aléas et peccadilles du code dans ce référentiel est ici une unité qui fonctionne dans Delphi 10 Seattle.

Notez qu'un type de compte spécifié peut avoir plusieurs comptes enregistrés, ce qui explique pourquoi ce code renvoie un tableau d'entre eux.

unit AccountEmailsU; 

interface 

function GetAccountEmails(const AccountType: String): TArray<String>; 

implementation 

uses 
    Androidapi.Helpers, 
    Androidapi.Jni, 
{$IF Declared(RTLVersion) and (RTLVersion >= 31)} 
    // Delphi 10.1 Berlin adds in full imports for the accounts classes 
    Androidapi.JNI.Accounts; 
{$ELSE} 
    Androidapi.JNIBridge, 
    Androidapi.JNI.App, 
    Androidapi.JNI.GraphicsContentViewText, 
    Androidapi.JNI.JavaTypes, 
    Androidapi.JNI.Os; 

type 
// ===== Forward declarations ===== 

    JAccount = interface;//android.accounts.Account 
    JAccountManager = interface;//android.accounts.AccountManager 

// ===== Interface declarations ===== 

    JAccountClass = interface(JObjectClass) 
    ['{94EE6861-F326-489F-8919-E20B39E3D9C1}'] 
    end; 

    [JavaSignature('android/accounts/Account')] 
    JAccount = interface(JObject) 
    ['{71476381-8B6E-471F-9189-9857ECD7508C}'] 
    function _Getname: JString; cdecl; 
    function _Gettype: JString; cdecl; 
    property name: JString read _Getname; 
    property &type: JString read _Gettype; 
    end; 
    TJAccount = class(TJavaGenericImport<JAccountClass, JAccount>) end; 

    JAccountManagerClass = interface(JObjectClass) 
    ['{96273844-2D84-47F0-BFD5-14B73402F843}'] 
    {class} function &get(context: JContext): JAccountManager; cdecl; 
    end; 

    [JavaSignature('android/accounts/AccountManager')] 
    JAccountManager = interface(JObject) 
    ['{9FA4077B-4628-433C-BAFC-9EB299DA9C98}'] 
    function getAccountsByType(type_: JString): TJavaObjectArray<JAccount>; cdecl; 
    end; 
    TJAccountManager = class(TJavaGenericImport<JAccountManagerClass, JAccountManager>) end; 
{$ENDIF} 

function GetAccountEmails(const AccountType: String): TArray<String>; 
var 
    AccountManager: JAccountManager; 
    Accounts: TJavaObjectArray<JAccount>; 
    Account: JAccount; 
    AccountLoopCounter: Integer; 
begin 
{$IF RTLVersion >= 30} 
    AccountManager := TJAccountManager.JavaClass.get(TAndroidHelper.Context); 
{$ELSE} 
    AccountManager := TJAccountManager.JavaClass.get(SharedActivityContext); 
{$ENDIF} 
    if AccountManager <> nil then 
    begin 
    Accounts := AccountManager.getAccountsByType(StringToJString(AccountType)); 
    if Accounts <> nil then 
    begin 
     SetLength(Result, Accounts.Length); 
     for AccountLoopCounter := 0 to Pred(Accounts.Length) do 
     begin 
     //Account := Accounts.Items[AccountLoopCounter]; 
     Account := TJAccount.Wrap(Accounts.GetRawItem(AccountLoopCounter)); 
     Result[AccountLoopCounter] := JStringtoString(Account.name); 
     end 
    end; 
    end; 
end; 

procedure RegisterTypes; 
begin 
    TRegTypes.RegisterType('AccountEmailsU.JAccount', TypeInfo(AccountEmailsU.JAccount)); 
    TRegTypes.RegisterType('AccountEmailsU.JAccountManager', TypeInfo(AccountEmailsU.JAccountManager)); 
end; 

initialization 
    RegisterTypes; 
end. 
+0

Notez les exemples d'utilisation dans la réponse étendue à http://stackoverflow.com/a/39581114/2817399 - la note pour vous assurer que vous avez la bonne autorisation est importante. – blong