I need to use a picture in a webview to zoom it
I succeded to set apicture in the sdcard of the emulator to simulate the work of the picture in a webview but I don't know how to set it in the final apk package.
The picture is called map.png and is set either in drawable and assets but I unsuccessfully tried many way to load it in the ...loadUrl(...)
This is my code I wish someone can help me.
public class Map extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
WebView myWebView = (WebView) findViewById(R.id.webMap);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("file://mnt/sdcard/map.png");
This is the new edited code that works in the emulator from asset, where do I have to put your new code to make anything working from the package.
myWebView.setWebViewClie开发者_开发技巧nt(new WebViewClient());
myWebView.loadUrl("file:///android_asset/map.png");
setContentView(myWebView);
Please, use my picture filename otherwise I don't understand it.
Again. I am...
I have a basic way for this.. just put your files in Assets directory and at runtime copy that files in either Internal storage or External Storage(sdcard).
like,
try {
// Open your local file as the input stream
InputStream myInput = myContext.getAssets().open("image.png");
// Path to the just created empty file
String outFileName = "/data/data/<Package Name>/files/newImage.png";
OutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0)
{
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
catch (Exception e)
{
Log.e("error", e.toString());
}
精彩评论