标签:
结果:
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 type 11 TForm1 = class(TForm) 12 Label1: TLabel; 13 Button1: TButton; 14 procedure Button1Click(Sender: TObject); 15 private 16 { Private declarations } 17 public 18 { Public declarations } 19 end; 20 21 var 22 Form1: TForm1; 23 24 implementation 25 uses 26 //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 var 39 ShortcutIntent: JIntent; 40 addIntent: JIntent; 41 wIconIdentifier: integer; 42 wIconResource: JIntent_ShortcutIconResource; 43 {$ENDIF} 44 begin 45 {$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 shortcut 58 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.
标签:
原文地址:http://www.cnblogs.com/FKdelphi/p/4781961.html