Tuesday, September 10, 2013

Android Tip - Auto-launch your App on Bootup


For corporate applications, it is not uncommon for enterprises to require their specific applicatons to be automatically launched when the device starts up.

To ensure your application is launched automatically upon device bootup, add a new Java Class file to the project and name it as BootupReceiver.java. Populate the BootupReceiver.java class as follows:

package net.learn2develop.autostartup;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class BootupReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "App started",
            Toast.LENGTH_LONG).show();

        //---start the main activity of your app---
        Intent i = new Intent(context, MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

Add the following statements in bold to the AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.learn2develop.autostartup"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name=
        "android.permission.RECEIVE_BOOT_COMPLETED"/>
   
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name=
                    "android.intent.action.MAIN" />

                <category android:name=
                    "android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".BootupReceiver">
            <intent-filter>
                <action android:name=
                   "android.intent.action.BOOT_COMPLETED" />
                <category android:name=
                   "android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
       
    </application>

</manifest>


That’s it! Your application will now be automatically launched when the device has finished the bootup process.

Android Tip - Checking Availability of Google Play Services


Nowadays, most of the services in Android are encapsulated in Google Play Services. For example, the latest version of Google Maps for Android is based on the Google Play services APK. Another feature that is based on Google Play services is the Fused Location Provider. Moving all the critical services into the Google Play services APK allows Google to deliver updates to core services much more quickly, without replying on carrier or OEM system image updates.

As such, it is important that your application checks the device that it is running on to ensure that the device has the Google Play services APK installed.

You can make use of the isGooglePlayServicesAvailable() method from the GooglePlayServicesUtil class to check if the target device has the Google Play services APK:

import com.google.android.gms.common.GooglePlayServicesUtil;
...
        int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
        // ---if Google Play services is available---
        if (ConnectionResult.SUCCESS == resultCode) {
            Log.d("Location Updates",
                "Google Play services is available.");
        } else {
            //---Google Play services was not available for
            // some reason---
            Log.d("Location Updates",
                "Google Play services is not available."); 
        }

Monday, September 09, 2013

Getting all ready for the Raspberry Pi course on 12 Sep!


Getting all geared up for the Raspberry Pi and Python Programming course this week on the 12 Sep 2013! This is going to be a super fun course! Will be bringing LCD screens, PiFace, Webcams, Pi Camera, and more! If you have missed this session, don't worry! The next run is on the 1 Oct 2013. Hope to see you at the course!!!

Monday, September 02, 2013

Additional topics added to the Raspberry Pi Course on 12 Sep 2013 (Thur)

Next week's Raspberry Pi course is going to be super fun as I have just finished working on the course materials. Among the key topics that I have indicated in the outline, like:

  • Getting Started with Raspberry Pi
  • Learning Python

I have also included some additional topics that are super fun:

  • Interfacing with a 16x2 LCD display using the Pi Cobbler Kit
  • Streaming video using a USB webcam
  • How to setup a Web server on the Raspberry Pi
  • How to remote login to the Raspberry Pi
  • How to interface with the PiFace board to connect to external devices

 

Course outlines and application form here.


Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
12 Sep 2013 (Thu)

Time
9am to 5pm

Fee
S$599

Wednesday, August 28, 2013

Raspberry Pi Course is now confirmed! - 12 Sep 2013


I am excited to announce that the Raspberry Pi course is now confirmed! Each participant will get the following:




HRD101 – 1-Day Getting Started with Raspberry Pi and Python Programming


The Raspberry Pi is a low-cost (US$35) credit-sized computer that connects to your TV and keyboard. Running Linux as the operating system, it can be used for many purposes such as word-processing, games, spreadsheets, web browsing, and more; almost everything that you can do with a regular computer. What’s more, usng the Raspberry you can connect the  general purpose input and output (GPIO) pins right on the board to drive external hardware such as LEDs, motors, and relays. Programming on the Raspberry Pi is made simple using the Python language. Hence, this course will get you started with Raspberry Pi and the Python programming language.

Topics
Setting up the Raspberry Pi
    Preparing the SD Card
    Booting up the Raspberry Pi
    Configuring the Raspberry Pi
    Troubleshooting
Getting around Linux on the Raspberry Pi
    Command Line
    Installing Useful Applications
Programming Python on the Raspberry Pi
    Hello World!
    Reserved Words
    Language syntax
    Objects and Modules
    Troubleshooting
    Using IDLE

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
12 Sep 2013 (Thu)

Time
9am to 5pm

Fee
S$599

Sunday, August 25, 2013

Xamarin Course on 2-4 Oct 2013

In this 3-day workshop, you will learn the fundamentals of building cross-platform mobile apps targeting iOS and Android devices using Xamarin and C#.

Using the Xamarin Studio, you cannow write iOS and Android apps using your familiar C# language. When you are ready to deploy your apps, the Xamarin compiler will compile your app into the native binary for each platform. The end result is you have a first class application that is optimized for the respective platform that it is compiled for.

Topics
• Introduction to Xamarin and Xamarin Studio
• HelloWorld using Xamarin Studio
• Using the emulators and simulator
• Handling Screen Rotations
• User interface Design
• Multi-screen applications
• Files Handling & Data Storage
• Cross-platform Code Sharing for Android and iOS
    o Strategies for cross-platform code sharing
    o Web Services
    o Data Storage

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
2-4 Oct 2013 (Wed-Fri)

Time
9am to 5pm

Fee
S$1,495

Saturday, August 24, 2013

iOS Tip - Detecting Network Connectivity Type


An iOS device typically have a two ways to get connected to the Internet – Wi-Fi or 3G/4G. Typically in your application, you should refrain from downloading large amount data when the user is connected to the 3G network. Instead, all the heavy downloading should be done when the user is connected to WiFi. So how do you check if the device is connected to WiFi or 3G?

The easiest way to check if the connectivity option available on your iOS device is to use the Reachability class provided by Apple. To do so, download the code sample from: https://developer.apple.com/library/ios/samplecode/reachability/Introduction/Intro.html and copy the Reachability.h and Reachability.m file into your own project.

Next, add a reference to the SystemConfiguration.framework in your project.

To use the Reachability class, import its header file:

#import "Reachability.h"

Finally, use the following code snippet to check the type of connectivity you have on your iOS device:

    Reachability *reachability =
        [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];
   
    NetworkStatus networkStatus =
        [reachability currentReachabilityStatus];
   
    if(networkStatus == NotReachable) {
        NSLog(@"No Internet");
    }
    else if (networkStatus == ReachableViaWiFi) {
        NSLog(@"Wi-Fi");
    }
    else if (networkStatus == ReachableViaWWAN) {
        NSLog(@"3G");
    }
    [reachability stopNotifier];

iOS Tip - Playing Sound


A very common task in iOS is playing sound. For example, your application needs to play some background audio when the user clicks on some buttons, etc.

You can make use of the AudioServicesPlaySystemSound() method in the AudioToolbox.framework to play back an audio file.

First, you need to add the AudioToolbox.framework to your project and then import its header file:

#import

Then, assuming your project has an audio file named c9.aiff, the following code snippet will play back the audio file:

    SystemSoundID soundID;   
    NSString *soundPath =
        [[NSBundle mainBundle] pathForResource:@"c9"
                                        ofType:@"aiff"];
    NSURL *soundPathURL = [NSURL fileURLWithPath:soundPath];
    AudioServicesCreateSystemSoundID(
        (__bridge CFURLRef)soundPathURL, &soundID);
    AudioServicesPlaySystemSound(soundID);

If you do not have an audio file and want to play the sound that is already available on your iOS device, you can specify the system sound ID directly, like this:
  
    int systemSoundID = 1304;
    AudioServicesPlaySystemSound (systemSoundID);

The list of system sound ID is available here: http://iphonedevwiki.net/index.php/AudioServices.



Wednesday, August 21, 2013

iOS Tip: Getting the Path to the Documents folder


Files created by your iOS applications are usually stored in the Documents folder of your application sandbox. Often, you need to obtain the path to this folder (you cannot hard-code this during design time as this is specific to each device).

The easiest way to get the path of the Documents folder of your application is to use the NSFileManager class, like this:

- (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager]
        URLsForDirectory:NSDocumentDirectory
               inDomains:NSUserDomainMask] lastObject];
}

Tuesday, August 20, 2013

iOS Tip: Disabling ARC for Specific Classes

Beginning with iOS 5, Apple has provided the Automatic Reference Counting (ARC) feature to free the developers from having to manually manage  the allocation and freeing of objects. However, if you are using some third-party libraries that have yet to support ARC, you can choose to selectively disable ARC for specific classes as ARC is a compiler feature.


To disable ARC for specific classes, select the project name in Xcode and select the Build Phases tab:


Expand the Compile Sources section then select the files representing the classes that you want to disable ARC. Press the Enter key and then enter the following statement in the pop-up window:

-fno-objc-arc


Press Enter and that’s it! The selected files will now compile without ARC. 

Saturday, August 17, 2013

Android Tip: Launching App Ops


In Android 4.3, Google has included an application known as App Ops. App Ops is an activity that allows users to enable/disable individual permissions of installed applications. Instead of granting a blanket of permissions during installation time, App Ops allows users to fine-tune the individual permission granted to applications.

At this moment, there is no way a user can directly go to the App Ops activity as it seems like Google is still fine-tuning the application (there are however, third-party apps on the Google Play that help you to do that – Permission Manager is a good example). However, if you are a developer, you can use the following intent to jump right into it:

startActivity(new Intent(
    "android.settings.APP_OPS_SETTINGS"));

This will launch the App Ops activity.

Friday, August 16, 2013

Foundation of Android Programming course on 16-17 Sep 2013 (Mon-Tue) is now confirmed!

The Foundation of Android Programming Course on 16-17 Sep 2013 (Mon-Tue) is now confirmed! If you have always wanted to create your own Android apps but were too busy to commit to learning it, this is your best chance.

This course is intensive and in 2 days you will get your Android apps up and running. Unlike other courses where you will sit through boring lectures, this course focuses on hands-on. You are expected to write code and deploy your apps onto your Android devices. 

To get the most out of this course, you are expected to have some basic programming experiences (such as C, C++, Visual Basic, Java, C#, etc). 

Enough said. You will find the 2 days the best investment you have ever made!

Venue
Bayview Hotel Singapore
30 Bencoolen Street 
Singapore 189621


Course Fee
S$997 (nett; no GST)
* applicable for PIC credit for companies; check with IRAS for your company's eligibility 

Duration
9am to 5pm

You need to bring along your own Windows or Mac laptop for the course.