我自己找到了解决方案,想和大家分享一下:
private WebResourceResponse getAppWebResourceResponseFromBlobstore(WebView view, String url) {
int slashIndex = url.lastIndexOf("blobservice?blob-key=");
String key;
key = url.substring(slashIndex + "blobservice?blob-key=".length());
System.out.println(key);
BlobstoreManager m = new BlobstoreManager(ctx, url);
return m.getBlob(key);
}
public class BlobstoreManager{
Context mContext;
String url;
public BlobstoreManager(Context c, String url) {
this.url = url;
this.mContext = c;
}
public WebResourceResponse getBlob(String key) {
String path = key;
File file = mContext.getFileStreamPath(key);
if(file.exists()) {
try {
System.out.println("Response from Blob");
return new WebResourceResponse("", "",mContext.openFileInput(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
FileOutputStream output = mContext.openFileOutput(path, Context.MODE_PRIVATE);
response.getEntity().writeTo(output);
output.flush();
output.close();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
System.out.println("Save new Blob");
return new WebResourceResponse("", "",mContext.openFileInput(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}