Android執行個體-為程式建立捷徑(未測試)

來源:互聯網
上載者:User

標籤:

結果:

1.因為只有小米手機,沒有三星手機,沒法測試。如果哪位神測試過的話,記得M我哦,謝了。

 

執行個體代碼: 

 1 unit Unit1; 2  3 interface 4  5 uses 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 8   FMX.Controls.Presentation; 9 10 type11   TForm1 = class(TForm)12     Label1: TLabel;13     Button1: TButton;14     procedure Button1Click(Sender: TObject);15   private16     { Private declarations }17   public18     { Public declarations }19   end;20 21 var22   Form1: TForm1;23 24 implementation25 uses26   //Androidapi.JNI.JavaTypes, 網上的大神說引入,但我沒看到哪裡要用27   //FMX.Platform.Android,28   //AndroidApi.Jni.App,29   AndroidAPI.jni.OS,//需要引入30   Androidapi.JNI.GraphicsContentViewText,//需要引入31   AndroidApi.JniBridge,//需要引入32   Androidapi.Helpers;//需要引入33 {$R *.fmx}34 {$R *.NmXhdpiPh.fmx ANDROID}35 36 procedure TForm1.Button1Click(Sender: TObject);37 {$IFDEF ANDROID}38 var39   ShortcutIntent: JIntent;40   addIntent: JIntent;41   wIconIdentifier: integer;42   wIconResource: JIntent_ShortcutIconResource;43 {$ENDIF}44 begin45   {$IFDEF ANDROID}46   ShortcutIntent := TJIntent.JavaClass.init(SharedActivityContext, SharedActivityContext.getClass);47   ShortcutIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);48 49   addIntent := TJIntent.Create;50   addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_INTENT, TJParcelable.Wrap((shortcutIntent as ILocalObject).GetObjectID));51   addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_NAME, StringToJString(Application.Title));52   addIntent.setAction(StringToJString(‘com.android.launcher.action.INSTALL_SHORTCUT‘));53 54   // get icon resource identifier //請將底線紅色部分改為你的項目名稱即可,其它不用修改。55   wIconIdentifier := SharedActivity.getResources.getIdentifier(StringToJString(‘ic_launcher‘), StringToJString(‘drawable‘), StringToJString(‘com.embarcadero.Project1‘));56   wIconResource := TJIntent_ShortcutIconResource.JavaClass.fromContext(SharedActivityContext, wIconIdentifier);57   // set icon for shortcut58   addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_ICON_RESOURCE, TJParcelable.Wrap((wIconResource as ILocalObject).GetObjectID));59 60   SharedActivityContext.sendBroadcast(addIntent);61   {$ENDIF}62 end;63 64 end.

 

Android執行個體-為程式建立捷徑(未測試)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.