Retrieving Current Network Status in Android

Here is a quick snippet of code which will help us in getting the current status of an Android device’s data connection.  We make use of the ConnectivityManager class to get current active network information. We try to catch a NullPointerException which is thrown by the isConnected method when there is no active data connection.

/**
 * Returns availability of a data connection
 * @param mContext
 *            Context of app
 * @return True is data connection is available , false otherwise
 */
public static boolean isDataConnectionOn(Context mContext) {
	ConnectivityManager connectionManager = (ConnectivityManager) mContext
			.getSystemService(Context.CONNECTIVITY_SERVICE);
	try {
		if (connectionManager.getActiveNetworkInfo().isConnected()) {
			Log.d("ConStatus", "Data Connection On");
			return true;
		} else {
			Log.d("ConStatus", "Data Connection off");
			return false;
		}
	} catch (NullPointerException e) {
		// No Active Connection
		Log.d("ConStatus", "No Active Connection");
		return false;
	}
}

To check whether an element exists using jQuery

To check whether element is present or not use following code in jQuery:-

If we use following code for checking tag it will always return true as
jQuery always returns object.

if($(‘checkbox’)){

}

Correct way to do this is as follows:-

if ($(‘checkbox’).length > 0) {

}


To get Linux OS release

To get Linux OS release, give either of the following commands

1.$ uname -r
2.$ cat /proc/version


Code for resumable download

Another piece of code for PHP developers, useful in open source development.

Following is the function for application that needs functionality of resumable download.

public static function dl_file_resumable($file, $is_resume=TRUE)
{
//First, see if the file exists
if (!is_file($file))
{
die(“404 File not found!“);
}

//Gather relevent info about file
$size = filesize($file);
$fileinfo = pathinfo($file);

//workaround for IE filename bug with multiple periods / multiple dots in filename
//that adds square brackets to filename – eg. setup.abc.exe becomes setup[1].abc.exe
$filename = (strstr($_SERVER['HTTP_USER_AGENT'], ‘MSIE’)) ?
preg_replace(‘/\./’, ‘%2e’, $fileinfo['basename'], substr_count($fileinfo['basename'], ‘.’) – 1) :
$fileinfo['basename'];

$file_extension = strtolower($path_info['extension']);

//This will set the Content-Type to the appropriate setting for the file
switch($file_extension)
{
case ‘zip’: $ctype=’application/zip’; break;
default: $ctype=’application/force-download’;
}

//check if http_range is sent by browser (or download manager)
if($is_resume && isset($_SERVER['HTTP_RANGE']))
{
list($size_unit, $range_orig) = explode(‘=’, $_SERVER['HTTP_RANGE'], 2);
if ($size_unit == ‘bytes’)
{
//multiple ranges could be specified at the same time, but for simplicity only serve the first range
//http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
list($range_from, $extra_ranges) = explode(‘,’, $range_orig, 2);
}
else
{
$range_from = ”;
}
}
else
{
$range_from = ”;
}

//figure out download piece from range (if set)
list($seek_start, $seek_end) = explode(‘-’, $range_from, 2);

//set start and end based on range (if set), else set defaults
//also check for invalid ranges.
$seek_end = (empty($seek_end)) ? ($size – 1) : min(abs(intval($seek_end)),($size – 1));
$seek_start = (empty($seek_start) || $seek_end 0 || $seek_end < ($size – 1))
{
header(‘HTTP/1.1 206 Partial Content’);
}

header(‘Accept-Ranges: bytes’);
header(‘Content-Range: bytes ‘.$seek_start.’-’.$seek_end.’/’.$size);
}

//headers for IE Bugs (is this necessary?)
//header(“Cache-Control: cache, must-revalidate”);
//header(“Pragma: public”);

header(‘Content-Type: ‘ . $ctype);
header(‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”‘);
header(‘Content-Length: ‘.($seek_end – $seek_start + 1));

//open the file
$fp = fopen($file, ‘rb’);
//seek to start of missing part
fseek($fp, $seek_start);

//start buffered download
while(!feof($fp))
{
//reset time limit for big files
set_time_limit(0);
print(fread($fp, 1024*8));
flush();
ob_flush();
}

fclose($fp);
}


To get data from POST body in PHP

This may look a very simple and small piece of code, but it took me ages to work on this one and get it in a proper format hence thought of sharing it with all. I used this line of code to get the data from POST body. I hope this will help you with your PHP Development.

file_get_contents(‘php://input’);


BlackBerry Tablet and SDKs

The BlackBerry tablet OS is based on QNX Neutrino Micro Kernel OS.  The tablet will offer full OpenGL and POSIX support alongside web standards such as HTML5 (using WebWorks). RIM has also announced the PlayBook’s ability to handle Flash content via Flash 10.1, as well as Adobe AIR apps. The tablet is of 7-inch, 1024 x 600, capacitive multitouch display, a Cortex A9-based, dual-core 1GHz CPU, 1GB of RAM, and a 3 megapixel front-facing camera along with a 5 megapixel rear lens. The device is capable of 1080p HD video, and comes equipped with an HDMI port as well as a microUSB jack, 802.11a/b/g/n WiFi, and Bluetooth 2.1. The device clocks in at a svelte 5.1- by 7.6-inches, is only 0.4-inches thick, and weighs just 400g.

What is new for developers?

  • BlackBerry Tablet OS SDK for Adobe AIR  - enables developer to create applications for the BlackBerry PlayBook tablet. The SDK allows creating Adobe AIR applications and installs a plug-in for Adobe Flash Builder 4. The plug-in  creates Adobe ActionScript projects intended to run in the Adobe AIR runtime environment on the BlackBerry PlayBook tablet. The standard computer version of Adobe Air has full support for developing applications with web technologies such as HTML, JavaScript, CSS, XHTML and ActionScript, but tablet version supports only ActionScript. Hopefully, the new version in future will come with full support for HTML, javascript and CSS same as PC version of Adobe AIR.
  • BlackBerry WebWorks SDK for Tablet OS – enables developer to create applications based on web technologies such as JavaScript, HTML5 and CSS. This development approach allows you to use the same code to target both BlackBerry smartphones and tablets.

“Tablet OS SDK for Adobe AIR” VS “BlackBerry WebWorks SDK”

  • The AIR SDK is somewhat more comprehensive; it’s also more mature in a way, since it’s in the third beta, while the WebWorks SDK’s first come out.
  • Support for SWF files in AIR SDK would imply richer UI’s than WebWorks SDK.
  • ActionScript3 (AIR SDK) ought to be a faster and more CPU-efficient language than JavaScript (WebWorks SDK), as it has a strict mode (which is enabled by default) that makes it more of a statically typed language (like Java) than a dynamically typed one as JavaScript is (Python and Ruby).
  • AIR SDK provide some unique UI components and predefined skins and enable you to listen for events specific to the BlackBerry Tablet OS, such as a swipe down event from the top bezel (the touch-sensitive frame around the display area of the screen). Some of the very interesting features of AIR SDK.
    • Pickers (lists that allow your application to display complex information and that allow the user to select data from multiple columns).
    • Specialized events and event listeners to handle events for lists, media controls, toggle switches, and sliders.
    • Customizable skins that allow you to provide a consistent look and feel for the UI components in your application.
    • Interface functionality for the media player, including playback controls and scrubbing (the ability to drag the slider through a song or movie).
    • Tweening functionality to define animated transitions.
  • WebWorks SDK is fully open-source, and apps made using it will be compatible with RIM smartphones with minimal tweaking necessary. WebWorks is conversely aimed at folks who are either newer programmers, or simply more invested in web languages than anything else.
  • Right now it is pretty dicey to judge which SDK is better. Looking at the maturity level of the SDKs and overview by RIM, I assume that for complex and rich UI it is preferable to use AIR SDK because of its maturity and performance.

Hindustan Times writing about Indian War Comics

After the Bangalore Mirror, it is now Hindustan Times publishing a news about JiniBooks and Indian War Comics available on iPad.

We all are now aware about ‘Indian War Comics’ and ‘BraveHearts of Mumbai – 26/11′ are available on iPad via JiniBooks. Its an honest and sincere effort by TechJini to make the content available digitaly, via iPad. Soon the other comics released by Indian War Comics will be available on iPad and other tablets as well. We are glad this effort is paying off and different media is also taking a note of our effort.

Congrats again to all the team!


How to establish connection over “https” using NSUrlConnection in iPhone?

The default TLS (Transport Layer Security) policy should be sufficient, but if you want to get involved in this process you can do so by implementing following NSUrlConnection delegates.

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace
-(void)connection:(NSURLConnection *)conn didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge

    1. If the authentication method of the  “protectionSpace” is “NSURLAuthenticationMethodServerTrust”, you have two choices: First, Return No, if you want default TLS algorithm to kick in. Second choice is to Return Yes, if you  want to handle the authentication your self, this will result in calling the -“connection:didReceiveAuthenticationChallenge:” delegate.
    2. If you Return Yes in “protectionSpace”  you have once again two choices. First, cancel the connection by calling “-cancelAuthenticationChallenge:” on the challenge's sender. Second option is to call “useCredential:forAuthenticationChallenge:” on the challenge's sender. To get a credential, call  -[NSURLCredential initWithTrust:].

    Indian war heroes’ comics on iPad

    Today Bangalore mirror published a small write up about TechJini’s efforts to salute the war heroes of Indian army.

    Congrats to all TechJini team and especially Amit and Shyamal.

    About ‘Bravehearts of Mumbai’

    26/11/2008 is a sad day in Indian history, when the terrorists attacked the city of Mumbai. It was by brave effort of various Indian security forces like NSG, Mumbai Police the terror was brought to an end. Now Indian War Comics has immortalized story of one such hero, Maj Sandeep Unnikrishnan AC by launching their 3rd comic ‘Braveheart of Mumbai – 26/11’. The comic details Maj Sandeep Unnikrishnan’s valour while he was fighting Ajmal Kasab’s associates in Taj Hotel, during 60 hour Mumbai terror attacks in Nov 2008.

    Indian War Comics has also partnered with TechJini Solutions, a Bangalore based IT company, to publish the stories on Smartphones and tablets using JiniBooks, an interactive content publishing platform. JiniBooks, enables small to medium size publishers and authors to reach bigger audience via digital medium. Authors can not only have static content but also build interactive magazines. Jinibooks is currently available only as an iPad application and soon it will be available for Android based tablets like Samsung tab etc.


    Introduction to HTML 5 (part 1 of 10)

    HTML 5

    HTML is always considered as one of the important aspects of web development. Here, we are discussing about HTML5.

    HTML5 which is currently under development is the next major revision of the HTML standard. Like its immediate Predecessors HTML4.01 and XHTML 1.1 , HTML5 is a standard for structuring and presenting content on world wide web.

    This new standard incorporates features like video playback , drag and drop , geolocation, data storage , visiting websites offline , forms and many more.

    Here is a brief history of HTML5.

    HTML5 which is currently under development is the next major revision of the HTML standard.

    There was never any such thing as HTML 1

    The first official specification was HTML 2.0, published by the IETF, the Internet Engineering Task Force.

    Later on the role of the IETF was superceded by the W3C, the World Wide Web Consortium, where subsequent iterations of the HTML standard have been published.

    In the latter half of nineties HTML 4.01 was published.

    After HTML 4.01, the next revision to the language was called XHTML 1.0

    The content of the XHTML 1.0 specification was identical to that of HTML 4.01. No new elements or attributes were added.

    The only difference was in the syntax of the language.

    Valid XHTML 1.0 document requires all tags and attributes to be in lowercase. All attributes must be quoted.All elements must have a closing tag.

    These rules were similar to that of XML.So they were moving towards XML more.

    Then the W3C published XHTML 1.1.

    It seemed as if the W3C were losing touch with the day-to-day reality of publishing on the web as they were moving towards XML.

    They began working on XHTML 2

    XHTML 2 wasn’t going to be backwards compatible with existing web content or even previous versions of HTML

    Representatives from Opera, Apple and Mozilla were unhappy with this direction.

    They formed their own group: the Web Hypertext Application Technology Working Group, or WHATWG

    They started working on HTML Standard and came out with new revision HTML5

    The W3C uses a consensus-based approach: issues are raised, discussed, and voted on.

    At the WHATWG, issues are also raised and discussed, but the final decision on what
    goes into a specification rests with the editor. The editor is Ian Hickson.

    While HTML5 was being developed at the WHATWG, the W3C continued working on XHTML 2

    Later on W3C admitted that the attempt to move the web from HTML to XML just wasn’t working.

    Rather than start from scratch, they wisely decided that the work of the WHATWG should be used as the basis for any future version of HTML.

    Later on W3C announced that they will stop working on XHTML 2 and they will support WHATWG.

    There are two groups working on HTML5. The WHATWG is creating an HTML5 specification using its process of “commit then review.” The W3C HTML Working Group is taking that specification and putting it through its process of “review then
    commit.”

    TechJini Solutions
    TechJini Solutions is Bangalore, India based company working in the areas of software product engineering services and creating next generation software products that bring real business value. We take pride in our philosophy of taking on challenging problems and providing innovative and outstanding solutions. We are proud to develop applications on different mobile/tablet platforms including iPhone, iPad, BlackBerry and Android.

    Next time, we will look at Forms in HTML 5. Feel free to email me for more details – avidnyat@techjini.com


  • TechJini Solutions

  • © Copyright 2009 TechJini Solutions Private Limited. All Rights Reserved
    iDream theme by Templates Next | Powered by WordPress