كيفية استخدام اوامر Android Debug Bridge (adb) للتحكم في الهاتف
#3
وعليكم السلام ورحمة الله

فيما يلي مثال على كيفية استخدام أوامر ADB للتحكم في الهاتف في دلفي:

كود :
unit ADB; interface uses   SysUtils,   System.IOUtils,   System.Process,   System.Diagnostics.ProcessUtils; type   TADB = class   private     fADBPath: string;     fDevice: string;   public     constructor Create(adbPath: string; device: string);     procedure ExecuteCommand(command: string);   end; implementation constructor TADB.Create(adbPath: string; device: string); begin   fADBPath := adbPath;   fDevice := device; end; procedure TADB.ExecuteCommand(command: string); var   process: TProcess;   output: string; begin   process := TProcess.Create(fADBPath + ' ' + fDevice + ' ' + command);   process.Start();   process.WaitFor();   output := process.Output;   Debug.Print(output); end; end.


[size=1]هذا المث[/size]ال ينشئ كائنًا من فئة TADB. يأخذ هذا الكائن كوسيطين: مسار أداة ADB واسم الجهاز المراد التحكم فيه.
تستخدم الطريقة ExecuteCommand() لإرسال أمر ADB إلى الجهاز. يأخذ هذه الطريقة كوسيط واحد: الأمر الذي تريد إرساله.
فيما يلي مثال على كيفية استخدام هذا الكود:

كود :
uses   ADB; var   adb: TADB; begin   adb := TADB.Create('adb', 'localhost:5555');   adb.ExecuteCommand('shell ls'); end.


سيؤدي هذا الكود إلى طباعة قائمة بالملفات الموجودة في دليل الجذر للجهاز.
يمكنك استخدام هذا المثال كأساس لإنشاء تطبيقات مخصصة للتحكم في الهاتف باستخدام أوامر ADB. على سبيل المثال، يمكنك إنشاء تطبيق لفتح التطبيقات أو إيقاف تشغيلها أو تغيير إعدادات الجهاز.

كود :
uses   ..., Process; procedure ExecuteAdbCommand(const ACommand: string); var   AProcess: TProcess; begin   AProcess := TProcess.Create(nil);   try     // Set the Adb executable and arguments     AProcess.Executable := 'adb';     AProcess.Parameters.Add(ACommand);     // Redirect the output to a stream     AProcess.Options := AProcess.Options + [poUsePipes];     AProcess.ShowWindow := swoHIDE;     // Start the process     AProcess.Execute;     // Read the output from the stream     while AProcess.Running do     begin       DoSomethingWithOutput(AProcess.Output);     end;   finally     AProcess.Free;   end; end; // Example usage: Restart the device procedure TForm1.RestartDevice; begin   ExecuteAdbCommand('shell reboot'); end;
قل: اللهم فاطِرَ السماوات والأرض عالم الغيبِ والشهادة، ربَّ كُلِّ شَيءٍ ومَلِيكَه، أَشْهد أن لا إله إلا أنت، أعوذ بك من شرِّ نفسي وشرِّ الشيطان وشِرْكِهِ وأن أقترف على نفسي سوءًا أو أجرُّه إلى مسلم
[-] كل من 1 user says قال شكرا ل Delphi4Us على المشاركة المفيدة
  • zohirbgn
الرد


الردود في هذا الموضوع
RE: كيفية استخدام اوامر Android Debug Bridge (adb) للتحكم في الهاتف - بواسطة Delphi4Us - 25-11-2023, 06:51 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم