Skip to content

Instantly share code, notes, and snippets.

@chethann
Last active May 4, 2021 03:50
Show Gist options
  • Save chethann/bd09b2ca4dfc0aab546cda1b9640d8a0 to your computer and use it in GitHub Desktop.
Save chethann/bd09b2ca4dfc0aab546cda1b9640d8a0 to your computer and use it in GitHub Desktop.
Sample code to create WebResourceResponse
public WebResourceResponse getWebResourceResponseFromAsset(String assetPath, String mimeType, String encoding) throws IOException{
InputStream inputStream = getActivity().getAssets().open(assetPath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int statusCode = 200;
String reasonPhase = "OK";
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put("Access-Control-Allow-Origin", "*");
return new WebResourceResponse(mimeType, encoding, statusCode, reasonPhase, responseHeaders, inputStream);
}
return new WebResourceResponse(mimeType, encoding, inputStream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment