0

Hope you can help me with the following:

I need to add an action in the Context Menu that pops up after a Long Press of an image in the Browser (the one that has 'Save Image', 'Copy Image', 'View Image', 'Set as a wallpaper', etc. )

As a result of choosing my action it should call my service and etc.... I don't want my app to overwrite all the context menu of the browser but only add an action to it. I haven't found any information on how to do this. Is it possible? Thanks!

see the image

akd
  • 6,538
  • 16
  • 70
  • 112

3 Answers3

0

Okay, if you want to add a context menu to the web view you will need to do the following. In the main application class that extends DroidGap you will need to add the following line to the onCreate method:

this.registerForContextMenu(this.appView);

then you'll need to add the following two methods to the same Java class:

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.example, menu);
}

Of course you'll need to update the R.menu.example to the name of your menu's XML file.

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.settings:
            this.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
            return true;
        case R.id.help:
            this.appView.sendJavascript("navigator.notification.alert('No help')");
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}

and in this method you'll need to handle all your menu option activities.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
0

In short, you can't do this. The browser is just an application like yours. If you were developing the browser, how you would expose such functionality from within your browser application?

Android gurus: Am I missing anything here?

As a side note, the closest you can come from doing that is define Intent.ACTION_VIEW and on resources and hope that the browser uses an IntentChooser, in which case, your app (along with others) would show up.

General actions are defined by the Android Intent system (http://developer.android.com/reference/android/content/Intent.html).

Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
  • I agree with you but one thing that dialer an app as well. When you install skype and if you try to dial a number or if you pick from a contact list it asks you whether you want to make the call over skype or dialer. Isnt it the same mechanism? I m not sure though. – akd Dec 20 '11 at 02:20
  • These can be done using the Intent resolution mechanism. Skype would have implemented something like ACTION_PICK. ACTION_NEW_OUTGOING_CALL also looks plausible (and interesting too!) – Vikram Bodicherla Dec 20 '11 at 02:23
0

In accordance to the above aswer. No you cannot add a menu item to any application. When you use call and see skype, its just that skype has capabilities of handling calls. And has registered in the Manifest. Hence, when the call action is raised all the applications with the Manifest registered will be given as option.

The similar behavior can be achieved by your application by simply declaring appropriate fields in the manifest file. For example if you want to handle the images all you need to do is handle the mime in data section of your intent filter.

Abhinava
  • 1,030
  • 9
  • 19
  • Please let me get it right. IF I do what you say in my app and install it on a device. And after that just go the native browser and go to a webpage long click an image in the page and will I be able to see transfer that image to my app somehow? – akd Dec 20 '11 at 03:46
  • if you do what i say.. then when you click on an image (not long click as it will open the context menu) if the url is redirecting to the full image path then your application will be given as an option (if you have registered your application for that particular mime). – Abhinava Dec 20 '11 at 08:50