老外写的在桌面添加快捷方式(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;

相关阅读 >>

Delphi 字符串加密解密单元

Delphi showmainform := false 失效的解决办法

Delphi 秒计算分钟、小时函数

Delphi从excel读取数据存入数据库demo

Delphi 英文单词第一个字母大写

Delphi 手机号码库段号地区查询

Delphi单元文件基本结构

Delphi 每年、月、周、日的开始与结束的时间startofayear … startoftheyear … endofayear … endoftheyear

Delphi更改android亮度

Delphi 查找目录下文件(多文件查找)

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



打赏

取消

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

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

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

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

评论

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