concrete effect visible "palm eye" palm clap antique Lake:http://bbs.guwanch.com
PrivateString Imgurl = ""; /*** * Function: Long press the picture to save to the phone*/@Override Public voidOncreatecontextmenu (ContextMenu menu, View V, contextmenuinfo menuinfo) {Super. Oncreatecontextmenu (menu, V, menuinfo); Menuitem.onmenuitemclicklistener Handler=NewMenuitem.onmenuitemclicklistener () { Public BooleanOnmenuitemclick (MenuItem item) {if(Item.gettitle () = = "Save to Phone") { NewSaveImage (). Execute ();//Android 4.0 to use threads to access the network later}Else { return false; } return true; } }; if(VinstanceofWebView) {Webview.hittestresult result=( (WebView) v). Gethittestresult (); if(Result! =NULL) { intType =Result.gettype (); if(type = = WebView.HitTestResult.IMAGE_TYPE | | type = =WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {Imgurl=Result.getextra (); Menu.setheadertitle (Prompted); Menu.add (0, V.getid (), 0, "Save to Phone"). Setonmenuitemclicklistener (handler); } } } } /*** * function: Save picture with thread * *@authorWangyp **/ Private classSaveImageextendsAsynctask<string, Void, string>{@Overrideprotectedstring Doinbackground (String ... params) {string result= ""; Try{String SDcard=environment.getexternalstoragedirectory (). toString (); File File=NewFile (SDcard + "/download"); if(!file.exists ()) {File.mkdirs (); } intIDX = Imgurl.lastindexof ("."); String ext=imgurl.substring (IDX); File=NewFile (SDcard + "/download/" +NewDate (). GetTime () +ext); InputStream InputStream=NULL; URL URL=NewURL (Imgurl); HttpURLConnection Conn=(HttpURLConnection) url.openconnection (); Conn.setrequestmethod ("GET"); Conn.setconnecttimeout (20000); if(Conn.getresponsecode () = = 200) {InputStream=Conn.getinputstream (); } byte[] buffer =New byte[4096]; intLen = 0; FileOutputStream OutStream=Newfileoutputstream (file); while(len = inputstream.read (buffer))! =-1) {outstream.write (buffer,0, Len); } outstream.close (); Result= "Picture saved to:" +File.getabsolutepath (); } Catch(Exception e) {result= "Save failed!" " +E.getlocalizedmessage (); } returnresult; } @Overrideprotected voidOnPostExecute (String result) {MsgBox (Prompted, result); } }
Specific effects download App test: or follow the public number: