Android Tutorial Add shortcuts to your Android application

Status
Not open for further replies.

RiverRaid

Active Member
Licensed User
Longtime User
Strange Problem...

Hi.

I have a strange Problem...
my Mainfest:
B4X:
AddApplicationText(
<activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name="shortcutactivity" 
        android:label="ahaSmokefree" android:screenOrientation="unspecified">
    <intent-filter>
        <action android:name="android.intent.action.CREATE_SHORTCUT"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>)

The Code in Activity "shortcutactivity":
B4X:
Sub Activity_Create(FirstTime As Boolean)
 Dim shortcutIntent As Intent
 shortcutIntent.Initialize("", "")
 shortcutIntent.SetComponent("com.ahasoft.rauchfreiBETA/.main") '<--- change to match your package name / and target activity.
 shortcutIntent.PutExtra("from_shortcut", True)
 Dim In As Intent
 In.Initialize("", "")
 In.PutExtra("android.intent.extra.shortcut.INTENT", shortcutIntent)
 In.PutExtra("android.intent.extra.shortcut.NAME", "Shortcut Test")
 In.PutExtra("android.intent.extra.shortcut.ICON", LoadBitmap(File.DirAssets, "applogo.png"))
 Activity.SetActivityResult(-1, In)
 Activity.Finish
End Sub

If I want to create the Shortcut in Android (The Text and Symbol is correctly displayed under Widgets in the App Drawer) than there comes a ToastMessage "App not installed".

The PackageName and Activity is spelled correct. Du you have any ideas?

Thanks!
 

RiverRaid

Active Member
Licensed User
Longtime User
Im Quinte sure, i copied it via strg-c and strg-v Form the tools-package menu. Quote strange...
 

jamessp

Member
Licensed User
Longtime User
Good morning, I passed by Eriel the procedure and failed here, I downloaded the example and still did not work!
What did I do wrong?
:sign0085:
 

hookshy

Well-Known Member
Licensed User
Longtime User
I think it will be interesting to make an example by creating a shortcut that offers you the opportunity to
open app developed only with b4A ?
In this matter il will be more easy to open developed app !
Thank you!
Can you mouve this request to wish list ?
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

I am not able to Automatically create a shortcut once the application installs in my phone. I added the shortcut activity also Edited the manifest as per you mentioned.

Kindly let me know.

Regards,
SK
 

systems1

Member
Licensed User
Longtime User
I downloaded the Shortcut.zip. but when I run the app in my device it is not adding any shortcut to my homepage. and also please see the log
B4X:
LogCat connected to: B4A-Bridge: HTC HTC One S-352762055129851
--------- beginning of /dev/log/main
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:anywheresoftware.b4a.samples.test
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=anywheresoftware.b4a.samples.test/.main }
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=anywheresoftware.b4a.samples.test/.main }
** Activity (main) Pause, UserClosed = true **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=anywheresoftware.b4a.samples.test/.main }
no extras
Error starting intent: (Intent) Intent { act=android.intent.action.MAIN flg=0x30000000 cmp=anywheresoftware.b4a.samples.test/.main }
Installing file.
PackageAdded: package:anywheresoftware.b4a.samples.test
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=anywheresoftware.b4a.samples.test cmp=anywheresoftware.b4a.samples.test/.main }
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=anywheresoftware.b4a.samples.test/.main bnds=[275,674][400,816] }
** Activity (main) Pause, UserClosed = true **
PackageAdded: package:com.applicationcraft.appc879559867854baf8d3f24d59621f57e

Thanks and regards.
 

Nerdworld

Member
Licensed User
Longtime User
I had the same issue with "App is not installed." - but solved it!

Instead of using AddApplicationText simply use AddActivityText this way:

B4X:
AddActivityText(Shortcut,
        <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>)
 

b4auser1

Well-Known Member
Licensed User
Longtime User
Is it possible to obtain the value of android:label="Add Shortcut" in the Shortcutactivity ?
I create several shortcuts, but would prefer to have a single Shortcutactivity for all of them and need a label value to distinguish.
 

b4auser1

Well-Known Member
Licensed User
Longtime User
You can add any key / value you like to the intent and then read it with Activity.GetStartingIntent.
I do it in an auxilary activity, which is declared in the manifest.
But now I have to declare a separate auxilary activity for each Shortcut.
Then in each of these auxilary activities I add a key with an unique value.
I process the key/value in one usual activity, which is called from Shortcut to perform actions.
But how to reduce number of auxilary activities ?
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
I developed an application that download some apks and then install them into the device.
So, right now, I want to create a shortcut for every apk that I installed.

Is it possible?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…