老外写的在桌面添加快捷方式(DELPHI XE5 ANDROID)


本文整理自网络,侵删。

 Uses
Androidapi.JNI.GraphicsContentViewText, FMX.Helpers.Android,
Androidapi.JNI.JavaTypes, FMX.Platform.Android, AndroidApi.JniBridge, AndroidApi.Jni.App,
AndroidAPI.jni.OS;

 

procedure TForm1.FormCreate(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

//只适用于HeaderFooter,其他的要改下('com.embarcadero.HeaderFooterApplication')。

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;

相关阅读 >>

Delphi2007-Delphi2010 程序不出现在任务栏的方法

Delphi 如何将多个文件复制到一个

Delphi判断文件大小

Delphi jpg和bitmap互转转换的方法

Delphi的对象注销方法destroy和free的区别

Delphi指针长度

Delphi中组件label、edit、tag、memo、richedit

Delphi fdconnection查看所有表包含用户表和系统表

Delphi 中判断一个字符是中文的方法

Delphi中对进程内存进行读写

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



打赏

取消

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

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

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

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

评论

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