Adding self to menus on other applications

138 views
Skip to first unread message

Shade

unread,
Oct 17, 2008, 10:59:43 AM10/17/08
to Android Developers
Hello!
It is possible to add my activity to build-in browser's menu?
Working example wanted.

Thank you.

With respect,
Michael
PrinterShare team

stephane...@gmail.com

unread,
Oct 21, 2008, 5:10:22 AM10/21/08
to Android Developers
I'm sorry i d'ont have example

But you can find tutorial on code.google.com/android

good luck.

Shade

unread,
Oct 21, 2008, 6:31:02 AM10/21/08
to Android Developers
Hello!

If you mean Android Howto document:

Adding yourself to menus on other applications

You can also advertise your Activity's services so that other
Activities can add your activity to their own option menu. For
example, suppose you implement a new image handling tool that shrinks
an image to a smaller size and you would like to offer this as a menu
option to any other Activity that handles pictures. To do this, you
would exposes your capabilities inside an intent filter in your
manifest. If another application that handles photos asks Android for
any Activities that can perform actions on pictures, Android will
perform intent resolution, find your Activity, and add it to the other
Activity's options menu.
The offering application

The application offering the service must include an <intent-filter>
element in the manifest, inside the <activity> tag of the offering
Activity. The intent filter includes all the details describing what
it can do, such as a <type> element that describes the MIME type of
data that it can handle, a custom <action> value that describes what
your handling application can do (this is so that when it receives the
Intent on opening it knows what it is expected to do), and most
important, include a <category> filter with the value
android.intent.category.ALTERNATIVE and/or
android.intent.category.SELECTED_ALTERNATIVE (SELECTED_ALTERNATIVE is
used to handle only the currently selected element on the screen,
rather than the whole Activity intent.

Here's an example of a snip of a manifest that advertises picture
shrinking technology for both selected items and the whole screen.
<activity class="PictureShrink"> <!-- Handling class --
>
<intent-filter label="Shrink picture"> <!-- Menu label to
display -->
<action android:name="com.example.sampleapp.SHRINK_IT" />
<data android:name="image/*" /> <!-- MIME type
for generic images -->
<category android:name="android.intent.category.ALTERNATIVE " /
>
<category
android:name="android.intent.category.SELECTED_ALTERNATIVE" />
</intent-filter>
</activity>


I've tried it.
After adding that intent-filter (with fixed typos) Pictures
application still does not offer to shrink pictures.


<intent-filter label="Do something terrible">
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category
android:name="android.intent.category.SELECTED_ALTERNATIVE" />
</intent-filter>
Adding this to my manifest does not affect browser's menu too.

Maybe i am making something wrong but i don't know what. And i was
unable to find really working examples of such actions.

With respect,
Michael
PrinterShare team

PS SDK version 1.0_r1


On 21 окт, 13:10, "stephane.cast...@gmail.com"

Adrian A

unread,
Nov 18, 2008, 4:33:18 PM11/18/08
to Android Developers
Hi Michael,

Have you had any luck with this? What was the problem you had?

Many thanks in advance,
Adrian

On Oct 21, 4:31 am, Shade <sh...@printeranywhere.com> wrote:
> Hello!
>
> If you mean Android Howto document:
>
> Adding yourself to menus on other applications
>
> You can also advertise your Activity's services so that otherActivitiescan add your activity to their own optionmenu. For
> example, suppose you implement a new image handling tool that shrinks
> an image to a smaller size and you would like to offer this as amenu
> option to any other Activity that handles pictures. To do this, you
> would exposes your capabilities inside an intent filter in your
> manifest. If another application that handles photos asks Android for
> anyActivitiesthat can perform actions on pictures, Android will
> perform intent resolution, find your Activity, and add it to the other
> Activity's optionsmenu.
> The offering application
>
> The application offering the service must include an <intent-filter>
> element in the manifest, inside the <activity> tag of the offering
> Activity. The intent filter includes all the details describing what
> it can do, such as a <type> element that describes the MIME type of
> data that it can handle, a custom <action> value that describes what
> your handling application can do (this is so that when it receives the
> Intent on opening it knows what it is expected to do), and most
> important, include a <category> filter with the value
> android.intent.category.ALTERNATIVEand/or
> android.intent.category.SELECTED_ALTERNATIVE (SELECTED_ALTERNATIVE is
> used to handle only the currently selected element on the screen,
> rather than the whole Activity intent.
>
> Here's an example of a snip of a manifest that advertises picture
> shrinking technology for both selected items and the whole screen.
> <activity class="PictureShrink">                 <!-- Handling class --
>
>     <intent-filter label="Shrink picture">      <!--Menulabel to
> display -->
>         <action android:name="com.example.sampleapp.SHRINK_IT" />
>         <data android:name="image/*" />                 <!-- MIME type
> for generic images -->
>         <category android:name="android.intent.category.ALTERNATIVE" /
>
>         <category
> android:name="android.intent.category.SELECTED_ALTERNATIVE" />
>     </intent-filter>
> </activity>
>
> I've tried it.
> After adding that intent-filter (with fixed typos) Pictures
> application still does not offer to shrink pictures.
>
> <intent-filter label="Do something terrible">
>     <action android:name="android.intent.action.VIEW" />
>     <data android:scheme="http" />
>     <category android:name="android.intent.category.ALTERNATIVE" />
>     <category
> android:name="android.intent.category.SELECTED_ALTERNATIVE" />
> </intent-filter>
> Adding this to my manifest does not affect browser'smenutoo.
>
> Maybe i am making something wrong but i don't know what. And i was
> unable to find really workingexamplesof such actions.

Dianne Hackbod

unread,
Nov 18, 2008, 4:36:52 PM11/18/08
to android-d...@googlegroups.com
Note that this only works with applications that want to participate in the mechanism, and pretty much none of the built-in applications do this.  We moved away from this approach because managing the UI for an arbitrary number of additional items is a challenge.  Our preference these days is for the application to start a chooser activity from which the user can select what they want to do; see the Intent docs for info on this.

2008/11/18 Adrian A <aag...@avaya.com>



--
Dianne Hackborn
hac...@android.com

Peli

unread,
Nov 19, 2008, 5:58:07 AM11/19/08
to Android Developers
What are the specific problems here regarding to managing the UI?
Aren't menu items beyond six items shown as a scrollable list, anyway?

Peli

On Nov 18, 10:36 pm, "Dianne Hackbod" <hack...@android.com> wrote:
> Note that this only works with applications that want to participate in the
> mechanism, and pretty much none of the built-in applications do this.  We
> moved away from this approach because managing the UI for an arbitrary
> number of additional items is a challenge.  Our preference these days is for
> the application to start a chooser activity from which the user can select
> what they want to do; see the Intent docs for info on this.
>
> 2008/11/18 Adrian A <aaga...@avaya.com>
> hack...@android.com

Dianne Hackbod

unread,
Nov 19, 2008, 3:02:01 PM11/19/08
to android-d...@googlegroups.com
Having an arbitrarily large number of items added by other applications, mixed together with unrelated items from the main application, is really tough to provide a decent UI for.  I think it is better to have a single top-level menu item that goes to a chooser dialog of the actions to be performed (and the choose can show the normal app icons, instead of there needing to be some additional extra special icon associated with the activity for display in the menu, which we don't really support right now anyway).

2008/11/19 Peli <peli...@googlemail.com>



--
Dianne Hackborn
hac...@android.com

Peli

unread,
Nov 20, 2008, 5:06:27 AM11/20/08
to Android Developers
Regarding menu icons not being displayed, a workaround has been posted
in this thread: http://groups.google.com/group/android-developers/browse_frm/thread/3fed25cdda765b02

I agree that it makes sense to present an Activity chooser for well-
defined actions (like "Send"), but I guess there are also cases where
it makes more sense for an application to appear like an "extension"
to a specific application and be embedded in their menu (like adding
voice memo to a note in notepad). At least, I hope you will not drop
this functionality in the future, as we already make use of it :-)

I have a related question, regarding the example above:
voice memo would have to be notified if notes are deleted, so that the
recordings that are linked to a note URI can also be deleted.
We were thinking of sending a broadcast action in the notepad provider
ACTION_DELETED with the note URI that all interested extensions could
listen to. Could there be anything wrong with this approach?

We thought that this would be better and more efficient than
registering a ContentObserver that would have to listen in a
background service all the time, and then scan for the change.

Peli

Dianne Hackborn

unread,
Mar 11, 2009, 2:31:12 PM3/11/09
to android-d...@googlegroups.com
Doing a broadcast is definitely better than making people sit around watching all the time.  Still, it is better yet not to rely on either -- if you are relying on this to keep your data in sync, you can pretty much be guaranteed that one way or another in some situation you will get out of sync. :}

2008/11/20 Peli <peli...@googlemail.com>



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages