Add action on the Browser's context menu after an image long press?

断了今生、忘了曾经 提交于 2019-12-12 02:28:23

问题


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!


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




回答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.




回答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:

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



来源:https://stackoverflow.com/questions/8569975/add-action-on-the-browsers-context-menu-after-an-image-long-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!