by
126 13
4
9
6,948
9
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Easy-to-find
Specified
Debate
OpenSource
Popularity: 812nd place
Created
Modified Nov 12, 2014
Languagepascal
LicenseMIT_X11
OSAndroid

Install A Shortcut On Android With Delphi XE5 Firemonkey

http://www.fmxexpress.com/install-shortcuts-on-the-android-home-screen-with-delphi-xe5-firemonkey/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/34147/Install-A-Shortcut-On-Android-With-Delph?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
//Android permission required: //<uses-permission android:name=”com.android.launcher.permission.INSTALL_SHORTCUT”/> Uses Androidapi.JNI.GraphicsContentViewText, FMX.Helpers.Android, Androidapi.JNI.JavaTypes, FMX.Platform.Android, AndroidApi.JniBridge, AndroidApi.Jni.App, AndroidAPI.jni.OS; {$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}
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus