Hello first off I wanted to say that I am new into programming (I mainly deal with graphic design) and I am wanting to set up an application where I show an image gallery and the user can save the images to their device. I am using WebView since it is easiest on my and for right now I have an image displayed fine in the application using html. I would like the user to be able to long press to invoke the default browser "save as" or "set as wallpaper" actions.
Here is what I have as far as code in my java file:
package com.wallpapergallery.wjd;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.app.Activity;
public class WallpaperGallerybyWJDDesignsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView)findViewById(R.id.webview);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/www/index.html");
}
}
Of course then opens up the index page which I have a normal png placed on the page for testing. Before you answer I warn you I am very new to this so explained help with sample code so I can learn would be appreciated.
Once this is done my idea is to use an HTML5 gallery to show my wallpapers and allow the user to save/set as wallpaper.
Update 1: I have managed to have the long press work and give me back logcat info which is pretty exciting for me - now all I need to do is get that menu to popup like the browser does showing "Save Image" "View Image" "Set As Wallpaper" - Again any help is appreciated and please feel free to take my code fix it and teach me why you did that if you get it to work >_<
New Code:
package com.wallpapergallery.wjd;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.app.Activity;
public class WallpaperGallerybyWJDDesignsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView)findViewById(R.id.webview);
webview.setOnLongClickListener(listener);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/www/index.html");
}
private OnLongClickListener listener = new OnLongClickListener() {
public boolean onLongClick(View v) {
Log.i("test","worked");
return true;
}
};
}