標籤:
結果:
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執行個體-為程式建立捷徑(未測試)