DELPHI XE5 ANDROID在桌面添加快捷方式


本文整理自网络,侵删。

 介绍

本文章实现了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函数assignfile使用

Delphi 替换其他程序里面的函数为自己的函数

Delphi取得cxgrid 合计数

Delphi远程开机再配合远程控制

Delphi串口api函数

Delphi excel表格数据导入数据库

Delphi 分割文件合并文件的函数

Delphi 获取大于2g的物理内存大小

Delphi 从其它access数据导入数据到本地数据库

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...