Delphi 10 Seattle的Android应用程序的主屏幕上创建快捷方式


本文整理自网络,侵删。

 

这是使用Delphi 10 Seattle Android应用程序在主屏幕上创建快捷方式的方法。

要在主屏幕上创建快捷方式,您需要以下权限:

com.android.launcher.permission.INSTALL_SHORTCUT
由于无法在项目选项屏幕上设置此权限,因此请
直接编辑“ AndroidManifest.template.xml”。

<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="%package%"
        android:versionCode="%versionCode%"
        android:versionName="%versionName%"
        android:installLocation="%installLocation%">

    <!-- This is the platform API where NativeActivity was introduced. -->
    <uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="%targetSdkVersion%" />
<%uses-permission%>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <=追加
    <uses-feature android:glEsVersion="0x00020000" android:required="True"/>
创建快捷方式的代码如下所示:

uses
  Androidapi.Helpers, // SharedActivity
  Androidapi.JNI.Os, // TJParcelable
  Androidapi.JNI.App, // TAndroidHelper.GetJActivity
  Androidapi.JNIBridge, // ILocalObject
  Androidapi.JNI.GraphicsContentViewText, // JIntent
  Androidapi.JNI.JavaTypes; // StringToJString

procedure TForm1.Button1Click(Sender: TObject);
const
  AppName = 'com.embarcadero.Project1';
var
  ShortcutIntent, Intent: JIntent;
  wIconIdentifier: Integer;
  wIconResource: JIntent_ShortcutIconResource;
begin
  // 启动应用程序的Intent
  ShortcutIntent := TJIntent.JavaClass.init(TAndroidHelper.Context,
    TAndroidHelper.Context.getClass);
  ShortcutIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);

  // 用于创建快捷键的Intent
  Intent := TJIntent.Create;
  Intent.setAction
    (StringToJString('com.android.launcher.action.INSTALL_SHORTCUT'));

  // 指定在快捷键点击时启动的Intent
  Intent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_INTENT,
    TJParcelable.Wrap((ShortcutIntent as ILocalObject).GetObjectID));
  Intent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_NAME,
    StringToJString(Application.Title));

  wIconIdentifier := TAndroidHelper.Activity.getResources.getIdentifier
    (StringToJString('ic_launcher'), StringToJString('drawable'),
    StringToJString(AppName));
  wIconResource := TJIntent_ShortcutIconResource.JavaClass.fromContext
    (TAndroidHelper.Context, wIconIdentifier);
  Intent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_ICON_RESOURCE,
    TJParcelable.Wrap((wIconResource as ILocalObject).GetObjectID));

  // 如果没有这个的话,即使已经有了主页图标,也会再创建
  Intent.putExtra(StringToJString('duplicate'), False);

  TAndroidHelper.Context.sendBroadcast(Intent);
end;
运行此代码将在主屏幕上创建一个快捷方式。

相关阅读 >>

Delphi 获取剪切板图像

Delphi 7中ado控件打开access数据库文件

Delphi memo1 数字列设定取值范围

Delphi android实例-读取设备联系人(xe8+小米2)

Delphi 端口扫描器原理

Delphi中用tlistview显示数据库数据

Delphi -- gdi+ Delphi如何让 tgpimage 直接从流中加载图片

Delphi获取优盘的id

Delphi使用ado读写excel文件

Delphi 泛型数组 strsplit 字符串分割

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



打赏

取消

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

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

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

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

评论

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