本文整理自网络,侵删。
介绍
本文章实现了DELPHI XE5 ANDROID在桌面添加快捷方式,在之前的文章里,有一篇是介绍这个功能的,但是只有一些代码,没有具体的工程,现在提供一个具体的工程代码,直接编译安装,就可以进行测试了,有兴趣的可以下载来看下。
下面是主要代码,应该和之前的差不多
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 extractfileext() 获取文件后缀的函数
更多相关阅读请进入《Delphi》频道 >>