1

i just want to send an broadcast when launch shortcut after search i didn't find any solution and i find one idea its launch an activity with the No Display and send broadcast from it and i do that's like this

 <activity android:name=".activity.shortcut"
        android:exported="true"
        android:excludeFromRecents="true"
        android:theme="@style/AppTheme.Transparent"
        ></activity>

and the theme Transparent

   <style name="AppTheme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

and the code for install shortcut its

 Intent shortcutIntent = new Intent(getContext(), shortcut.class);


        shortcutIntent.putExtra("name","name");
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); //no effect
        //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); //no effect

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, conversationList.getFname());


        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, mBitmap);

        addIntent.putExtra("duplicate", false);
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getContext().sendBroadcast(addIntent);

after run the app and create the shortcut when i click on the shortcut its open all the app and send brodcast so i just want to open the activity without launch main activity in application or just send broadcast when click on shortcut

Medo Zeus
  • 99
  • 2
  • 9

1 Answers1

0

Use a shortcut to a different activity like

 <activity android:name="send">

Your app should have an activity called send and there in d onResume()

call code that sends the broadcast.

Or use a Dynamic intent and send some data part of the shortcut like

 setShortLabel("send-broadcasts") 

https://developer.android.com/guide/topics/ui/shortcuts.html#dynamic

tgkprog
  • 4,493
  • 4
  • 41
  • 70
  • i do that's and i have activity called `shortcut` but when i click on shortcut its launch all the app (Main Activity) i don't know why – Medo Zeus Mar 21 '18 at 23:28
  • https://stackoverflow.com/questions/17058617/how-create-homescreen-shortcut-to-resume-top-activity this might help – tgkprog Mar 22 '18 at 07:24