Tampilkan postingan dengan label SD Card. Tampilkan semua postingan
Tampilkan postingan dengan label SD Card. Tampilkan semua postingan

WebView - Part 4 Handling Cookies in WebView

Posted by muamar Sabtu, 21 Mei 2011 0 komentar

Handling Cookies in WebView

Actually this is very simple, as we mentioned in Part 1 of this series, that for security reasons, your application will have its own cache and its own cookie store i.e. it doesn’t share the Browser’s application data, cookies are also managed in separate thread which means that those operations which are for managing cookies (e.g. building index) will not block your application’s UI thread.

Now, we use “android.webkit.CookieSyncManager” class to manage cookies particularly to synchronize the browser cookies between RAM and permanent storage. To get maximum efficiency cookies are stored in RAM and a separate thread is used to save cookies this thread is driven by timer, sync interval is of 5 Minutes.

To use CookieSyncManager all you have to do is add these three lines in your code
Call this when the application starts.
 
CookieSyncManager.createInstance(context);
 
To set up sync call in Activity.onResume()
 
CookieSyncManager.getInstance().startSync();
 
and lastly, call this in Activity.onPause()
 
CookieSyncManager.getInstance().stopSync();
 
To get sync instantly without waiting for the timer to trigger, host can call
 
CookieSyncManager.getInstance().sync();
 
But be aware that this sync also happens asynchronously, so don’t do it just as your activity is shutting down.

<<WebView - Part 3 How to customize WebView?




Cheers!!
Vivek Jain
Hello Everyone, I came across an application which allowed me to produce nice effects on Images that are in my phone and Images that I take from my phones camera, its available here, 

Baca Selengkapnya ....

WebView - Part 2 Accesing Files on Device and in APK itself

Posted by muamar Kamis, 19 Mei 2011 0 komentar
Accessing files in Android device using WebView

For using WebView you must have the permissions to access INTERNET and to request permission to access INTERNET just add the following line in your application's manifest just under </application> tag  i.e. make it a child of manifest tag.

     <uses-permission android:name="android.permission.INTERNET"/>

Create the following HTML either programmatically using code in String format or create the file and save that in /res/value/string.xml and name it as <somename>
            <html>
          <head><title>Test File Loading</title></head>
          <body>
Here we are loading the image file in HTML
To display:<br>
<img height=”100” width=”100” src=file:///yourimagefilepath></img>
          </body>
     </html>

To reference the file in <img> tag, you have to use the file URI pointing to the location where the file is saved.

Here’s the Java code to load this HTML into a WebKit component:
            WebView web = (WebView)findViewById(R.id.web_view);
            final String mimeType = “text/html”;
     final String encoding = “UTF-8”;
String htmldata =
          getResources().getString(R.string.<somename>);
     if(htmldata != null){
          web.loadData(html,
                        mimeType,
                        encoding);
     }
else{
web.loadData(“<html><body>Failed</body></html>”
     ,mimeType, encoding);
}

Now, you should be able to see image in your WebView

Accessing resources bundled with APK
Create the following HTML either programmatically using code in String format or create the file and save that in /res/value/string.xml and name it as <somename>
            <html>
          <head><title>Test File Loading</title></head>
          <body>
Here we are loading the image file in HTML
To display:<br>
<img height=”100” width=”100” src=file:///android_asset/imagename></img>
          </body>
     </html>
To reference the file in <img> tag, you have to use the file URI pointing to the /android_asset/imagename.


Here’s the Java code to load this HTML into a WebKit component:
            WebView web = (WebView)findViewById(R.id.web_view);
            final String mimeType = “text/html”;
     final String encoding = “UTF-8”;
String htmldata =
          getResources().getString(R.string.<somename>);
     if(htmldata != null){
          web.loadData(html,
                        mimeType,
                        encoding);
     }
else{
web.loadData(“<html><body>Failed</body></html>”
     ,mimeType, encoding);
}

Now, you should be able to see image in your WebView.

<<WebView – Part 1 Capabilities and Limitations  

WebView - Part 3 How to customize WebView?>>


Cheers!!
Vivek Jain
Hello Everyone, I came across an application which allowed me to produce nice effects on Images that are in my phone and Images that I take from my phones camera, its available here, 


Baca Selengkapnya ....
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android list.