12

I am working on an android app that receives content from another apps sharing it via an android intent. I did the intent filter to receive the shared content into the app, but I saw that apps like Pocket made that without leaving the original app with an overlay over the app and I don't know how to do that. Does anyone know how to do that or give me some hints?

enter image description here

jesusbotella
  • 626
  • 4
  • 8
  • Could you share the solution if you've solved this? I'm trying to make a share overlay exactly like Pocket – Zen Sep 29 '16 at 00:21
  • The only thing that you need to do is to create an Activity with the content you want to show in the overlay. Set the theme as Nikola Despotoski wrote in the accepted answer and then set an IntentFilter (https://developer.android.com/training/basics/intents/filters.html) to filter the content you want to receive. – jesusbotella Sep 30 '16 at 10:10

3 Answers3

8

Start activity that has transparent theme with following attributes (test this on API 18 for bug):

<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>

Set child elements as you desire, as you would do in normal activity.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • this works, but it seems that taps are not passed through to the underlying app/activity. is there a way to create an overlay that allows interaction with the app/activity that's below it? – Ben H Dec 25 '14 at 22:17
  • 1
    The way to do the thing you want is to start a service that creates the overlay by means of the WindowManager Class and call the finish() method from the activity. Like Facebook Chat Heads. http://stackoverflow.com/questions/15975988/what-apis-in-android-is-facebook-using-to-create-chat-heads – jesusbotella Dec 30 '14 at 00:36
3

After receiving your Intent, you should start a Service which create and attach your View/ViewGroup on the Window. This will allow you to keep the calling application in foreground.

To create a floating overlay take a look here: http://www.piwai.info/chatheads-basics/

bonnyz
  • 13,458
  • 5
  • 46
  • 70
1

I would look at the WindowManager Class:

http://developer.android.com/reference/android/view/WindowManager.html

Here is a link to a question that better explains what it is:

What is WindowManager in android?

Community
  • 1
  • 1
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156