FlurryAdNativeAsset secHqImageAsset = adNative.getAsset("secHqImage");
secHqImageAsset.getValue()
The url points to either the local or remote resource, depending on how the ad >space is configured on dev.flurry.com
Caching is enabled for the ad space - default setting: The SDK caches the assets onto the device before it declares the ad ready. The asset’s url in FlurryAdNativeAsset points to the local file (url contains the locator in the form file:// ) where the asset resides.
Caching is not enabled for the ad space: The assets are available via https url. Calling loadAssetIntoView or getAssetView on the FlurryAdNativeAsset object loads the assets directly from the network and does not cache the assets.
https://developer.yahoo.com/flurry/docs/publisher/code/android/
I cannot find anywhere in ad space to disable caching and I want to get the exactly remote link and load the image manually because keep using getAsset("secHqImage").loadAssetIntoView() will cause memory leak.
Is there any way to get the remote url link?
FlurryAdNativeAsset secHqImageAsset = adNative.getAsset("secHqImage");
Now you have the FlurryAdNativeAsset.
secHqImageAsset.getValue()
Should be replaced with:
String urlOfAsset = secHqImageAsset.getValue();
That should give you the URL string from where to get the asset. Once you get it, just use Android provided methods to load the Bitmap of the image.
Related
Basically, I am making an API call to get some kind of response back. In this response, there is some field like socialImageUrl that points to a URL string that references an image. There is other data there besides the URL. I am caching that entire response.
So I turn off wifi and LTE, and I checked that I had no internet connection by doing stuff on the browser. I go back into my app and I trigger my LruCache and retrieved the cached response (I know I got it because of logging) and I use that response to render my page.
What I expected: I would see all the data that I cached on the page but anything that used the image URLs will give out some erroneous image or maybe the page doesn't even load at all because there is some error with that image URL seeing as it can't access the internet
What actually happens: I see all of the data I cached and I also see the images
Any clue to what is going on? I'm not doing any image caching as far as I know. I am using react-native's vanilla Image JSX component. I am also on Android.
I was also in this situation ones, sadly React-Native docs are not extensive for now.
The Android implementation of Image component has by default caching enabled for images of low size < 500 KB (the max size is not documented but you can just try images of varied size to check and this size could change in the future).
Note: Even in IOS the image's will be cached by default when using the Image component.
If I had to guess, lru cache does not support caching binary data like an image file.
If you need advanced <Image> performance caching or for the remote image to be permanently stored to local disk for offline app use you can use my higher order component module that upgrades native <Image>
React Native Image Cache HOC
Tl;DR Code Example:
import imageCacheHoc from 'react-native-image-cache-hoc';
const CacheableImage = imageCacheHoc(Image);
export default class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<CacheableImage style={styles.image} source={{uri: 'https://i.redd.it/rc29s4bz61uz.png'}} />
<CacheableImage style={styles.image} source={{uri: 'https://i.redd.it/hhhim0kc5swz.jpg'}} permanent={true} />
</View>
);
}
}
The first image will be cached until the total local cache grows past 15 MB (by default) then cached images are deleted oldest first until total cache is below 15 MB again.
The second image will be stored to local disk permanently. People use this as a drop in replacement for shipping static image files with your app, but you could use it so that your app displays image content even when user is offline.
If you need to grab all the image files from the network up front (before the <CacheableImage> is rendered by react native) then just use the following CacheableImage static method to pre-fetch the files:
import imageCacheHoc from 'react-native-image-cache-hoc';
const CacheableImage = imageCacheHoc(Image);
CacheableImage.cacheFile('https://i.redd.it/hhhim0kc5swz.jpg', true)
.then( localFileInfo => {
console.log(localFileInfo);
// Console log outputs:
//{
// url: 'https://i.redd.it/rc29s4bz61uz.png',
// cacheType: 'permanent',
// localFilePath: '/this/is/absolute/path/to/file.jpg'
//}
});
I am using XE7 Rad Studio to build "apps" for Android and IPhone. Focusing on Android for the moment.
According to the requirements, I need to load the HTML inside the application as a resource string.
WebBrowser1.LoadFromStrings(ResourceStrings.HTMLString,'');
//Loads the resource-string successfully.
However in this resource-string I need to load images, and I cant figure out how to do it. I can see in deployment that I have the images loaded into the project {Bitmap_1, Bitmap_2,Bitmap_3}.
How do I complete this line:
resource-string:
...'<img id="img2" class="thumbnail" src="/images/im2.bmp" alt="/images/im2.bmp"/>'...
Many thanks.
If you read the documentation for LoadFromStrings(), it says:
Displays HTML string content within the TWebBrowser component.
This method uses the following parameters:
Content: specifies the HTML string to be displayed.
BaseUrl: specifies a path that is used to resolve relative URLs within the loaded page. To clarify, consider the following scenario: this parameter is set to www.mycompany.com/departments/, and the loaded page defines a link <a href=’Sales.html’>Sales dept</a>. In the given case, clicking this link opens http:// www.mycompany.com/departments/Sales.html.
That is the exact scenario you are running into. Your HTML contains relative links to external images, but you are not providing a BaseURL, so the WebBrowser cannot resolve the correct URLs it needs to load those images.
In the Deployment Manager, set the Remote Path of your image files to either StartUp/Documents/images/ or StartUp/Library/Application Support/images/.
At app startup, Delphi will copy files beginning with StartUp to the appropriate folder on the device. Then you can do the following when calling LoadFromStrings():
// note sure which function to use for 'StartUp/Library/Application Support/',
// maybe TPath.GetLibraryPath()? This example is for '/StartUp/Documents/'...
WebBrowser1.LoadFromStrings(ResourceStrings.HTMLString, 'file://' + TPath.GetDocumentsPath);
That will allow "/images/im2.bmp" to resolve to something like file:///data/data/<application ID>/files/images/im2.bmp", etc.
When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)
In my app, am loading a local html which is residing in SD card as
String extPath = getExternalFilesDir(null).toString();
String html = getHtml(extPath+File.separator+fileName); //it just reads html file and returns content as string
webvu.loadDataWithBaseURL("file://"+extPath+File.separator,html ,
"text/html","UTF-8", null);
the html file loaded in the web view (webvu) tries to load another html file with $.load ajax call
$.load("base.html",function(){ ... });
ajax load is throwing the below error. How can I resolve this
XMLHttpRequest cannot load
file:///storage/emulated/0/Android/data/com.example.sdcardwebview/files/sec.html.
Cannot make any requests from null. at null:1
I finally figured out the solution
The null origin issue happens only in JB, which supposedly has a webview based on new webkit which implements stricter same origin policy.
Hence the code in question works perfectly fine on all version of android below JB. To get the code work on JB, all we need to do is change web view settings. Just call
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
I want to get images from the web page and save them into the local storage. I can find all image URLs from the HTML, load that images from the server and save them. But I don't want to access to the server second time for the same information which is already in webview. So I want to know how I can load images from the webview?
You can set a WebView cache in a few steps. Take a look below.
WebView webView = (WebView) findViewById(R.id.your_webView_Id);
String cacheDir = getDir("your_WV_cache_dir", Context.MODE_PRIVATE).getAbsolutePath();
webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 1); // 1 Mb cache limited size > webView.getSettings().setAppCachePath(cacheDir);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // This constant is important to you. This way you can load daa from cache, if it was already downloaded once.
You might take a look to th other possible values to the constant above at the WebView.WebSettings official documentation.
Let me know if it works.