1

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;

    }

 };

}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
IMWJD
  • 11
  • 1
  • 4

1 Answers1

1

I BELIEVE this is what your looking for, android set image as contact icon/wallpaper, specifically the Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA); setAs.setType("image/jpg"); part. I'm not entirely sure this is what your looking for, but if its not exactly right, it should get you on the right track.

Community
  • 1
  • 1
r2DoesInc
  • 3,759
  • 3
  • 29
  • 60
  • Where would I put this if the code above is my only code - would I need to put the intent in the manifest and that would enable it? – IMWJD Jan 30 '12 at 02:20
  • add a long click listener to your image view that launches the intent. You wouldnt need to add anything to the manifest, those are only for new activities, like if you were clinking on an image that launched a new screen, that would need to be registered in the manifest, but its not the intent thats registered, its the activity . – r2DoesInc Jan 30 '12 at 02:24