Skip to content Skip to sidebar Skip to footer

Add Action On The Browser's Context Menu After An Image Long Press?

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', 'Co

Solution 1:

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

Solution 2:

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.

Solution 3:

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:

@OverridepublicvoidonCreateContextMenu(ContextMenu menu, View v,
                                ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflaterinflater= 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.

@OverridepublicbooleanonContextItemSelected(MenuItem item) {
    AdapterContextMenuInfoinfo= (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.settings:
            this.startActivity(newIntent(android.provider.Settings.ACTION_SETTINGS));
            returntrue;
        case R.id.help:
            this.appView.sendJavascript("navigator.notification.alert('No help')");
            returntrue;
        default:
            returnsuper.onContextItemSelected(item);
    }
}

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

Post a Comment for "Add Action On The Browser's Context Menu After An Image Long Press?"