本文整理自网络,侵删。
介绍
本文章介绍了Delphi XE6、XE5、XE7在Android创建快捷方式,创建的代码首先需要为应用添加权限INSTALL_SHORTCUT ,然后添加下面的代码,就可以实现这样的功能
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.MobilePreview, Androidapi.JNI.GraphicsContentViewText, FMX.Helpers.Android,
Androidapi.JNI.JavaTypes, FMX.Platform.Android, AndroidApi.JniBridge, AndroidApi.Jni.App,
AndroidAPI.jni.OS;
procedure THeaderFooterForm.Button1Click(Sender: TObject);
{$IFDEF ANDROID}
var
ShortcutIntent: JIntent;
addIntent: JIntent;
wIconIdentifier : integer;
wIconResource : JIntent_ShortcutIconResource;
{$ENDIF}
begin
{$IFDEF ANDROID}
ShortcutIntent := TJIntent.JavaClass.init(SharedActivityContext, SharedActivityContext.getClass);
ShortcutIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);
addIntent := TJIntent.Create;
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_INTENT, TJParcelable.Wrap((shortcutIntent as ILocalObject).GetObjectID));// here we need to cast the intent as it's not done in delphi by default, not like java
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_NAME, StringToJString(Application.Title));
addIntent.setAction(StringToJString('com.android.launcher.action.INSTALL_SHORTCUT'));
// get icon resource identifier
wIconIdentifier := SharedActivity.getResources.getIdentifier(StringToJString('ic_launcher'), StringToJString('drawable'), StringToJString('com.embarcadero.HeaderFooterApplication')); // if the app name change, you must change the package name
wIconResource := TJIntent_ShortcutIconResource.JavaClass.fromContext(SharedActivityContext, wIconIdentifier);
// set icon for shortcut
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_ICON_RESOURCE, TJParcelable.Wrap((wIconResource as ILocalObject).GetObjectID));
SharedActivityContext.sendBroadcast(addIntent);
{$ENDIF}
end;
相关阅读 >>
Delphi 如何将bitmap位图与base64字符串相互转换
Delphi debug模式下可以但是release模式下报错原因之一
Delphi xe6 取得app自己的版本号(横跨4个平台)
Delphi tidhttp+tidssliohandlersocket+ssl
更多相关阅读请进入《Delphi》频道 >>