Wednesday, September 2, 2015

Kids App — Android Alphabet Learning App with Text-to-Speech (English & Kannada)

I was trying to develop an Android app for my son which will help him learn the alphabets. I thought it may be helpful to others also so I'm sharing it on Google Play: Kids Application.

Overview

Kids App is a simple alphabet learning application for Android that combines text-to-speech with image-based learning. The app uses its own local database to store images, alphabets, words and pronunciation data. It currently supports two languages (English and Kannada) and two modes of operation (Manual and Auto). This is a draft version — we plan to add more languages and features.

Main features

  • Text-to-speech pronunciation for alphabets and numbers
  • Image and word display for each alphabet
  • Local database to store user-configured images, words and pronunciations
  • Two languages supported now: English and Kannada
  • Two operation modes: Manual (tap letters) and Auto (play-through)
  • Settings to configure images (camera or gallery), words and pronunciations

Languages

  • English
  • Kannada

We are going to enhance it for other languages also.

Modes of operation

Manual

Tap any alphabet to see the associated word and image and hear the pronunciation. For example: A for Apple.

Auto

The app automatically walks through all the alphabets and numbers, showing each item and pronouncing it without user tapping.

Configuration (customization)

The best part of this application is the ability for the user to configure their own word, image and pronunciation for each alphabet. For example, if your child's name is Krishna, you can set that name, an image and pronunciation for the letter K.

How to configure:

  1. Open the app and tap the menu button on the alphabet screen.
  2. Select "Configure".
  3. Choose an image from the camera or gallery, set the word, and provide pronunciation if needed.
  4. Save — the data is stored in the app database. To revert to defaults, use the "SetDefault" option.

Screenshots

These are the original screenshots from the post (kept as-is):

Splash and selection screen

Mode and language selection

Manual mode: alphabet screen

Example: A for Apple (image + TTS)

Numbers view

Configure menu and options

Configure: set image and word

Auto mode walkthrough

Kannada alphabet screen

Kannada: examples

Additional Kannada screen

App icon / Google Play link

How it works (technical)

  • The core code is written in Java and the GUI is developed using XML (standard Android components).
  • The app maintains a local database with images, words and pronunciations. User changes are saved locally until the user selects the default dataset.
  • Text-to-speech leverages Android's TTS engine for pronunciation.

Download

You can download the app from Google Play: Kids App on Google Play

Roadmap / planned enhancements

  • Add more languages
  • Add additional configuration options and improvements to the UI
  • Improve accessibility and TTS language detection

Notes and contact

This is a draft version — we are planning more features. Keep watching this post for updates.

If you have feedback or feature requests, install the app from the Play Store and send feedback through the app or comment on this post.

Tuesday, August 25, 2015

Enable or Disable an Android Button at Runtime (with network check)

While I was working with an Android application for a customer, there was a use case to disable a button at runtime and enable it after some action. This is straightforward in Android. Below I show the XML for the button, how to reference it in your activity, and how to enable/disable it based on network status using a small NetworkUtil helper (link provided).

Button XML

Use a standard Button in your layout (example):

<Button
    android:id="@+id/about_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="64dp"
    android:text="@string/about_label" />

Reference the Button in your Activity

In onCreate(), find the button and keep a reference. Using the Button type makes intentions clearer and provides button-specific APIs:

Button aboutButton = findViewById(R.id.about_button);

Note: on older Android APIs you may need a cast, e.g. Button aboutButton = (Button) findViewById(R.id.about_button);, but with modern SDKs the generic signature is available.

Enable and disable the Button

You can enable or disable a View (including Button) using setEnabled(true/false):

  • To enable:
aboutButton.setEnabled(true);
  • To disable:
aboutButton.setEnabled(false);

Disabling a button via setEnabled(false) also prevents it from receiving click events. For improved UX you may also want to change the visual appearance (alpha, color) so users can see the disabled state:

aboutButton.setEnabled(false);
aboutButton.setAlpha(0.5f); // visual cue
// when enabling back:
aboutButton.setEnabled(true);
aboutButton.setAlpha(1f);

Remember to make UI changes on the main thread.

Enable based on network status (using NetworkUtil)

I use a small helper class NetworkUtil to check network connectivity. You can download it here:

Create an instance and call getConnectivityStatus with a Context. Example usage (corrected and formatted):

NetworkUtil net = new NetworkUtil();
int status = net.getConnectivityStatus(getApplicationContext());
if (status != 0) {
    aboutButton.setEnabled(true);
    aboutButton.setAlpha(1f);
} else {
    aboutButton.setEnabled(false);
    aboutButton.setAlpha(0.5f);
}

Notes:

  • The original article had a typo setEnabled(flase); ensure you use false.
  • The meaning of status values depends on NetworkUtil implementation. Keep your app logic consistent with that helper's return values.

Accessibility and UX considerations

  • When disabling interactive elements, ensure assistive technologies can convey the change. Consider adding content descriptions for non-textual controls and ensuring focus behavior is appropriate.
  • Adjust visual indicators (alpha, color) so users can perceive the disabled state.

Alternatives and further improvements

  • For production apps consider using Android's ConnectivityManager and NetworkCallback APIs to observe connectivity changes rather than polling.
  • In modern architectures, expose connectivity status via LiveData, Flow, or other observable streams and observe from the Activity/Fragment to update UI reactively.

NetworkUtil download link (same as above): https://sites.google.com/site/karjolblogs/downloads/NetworkUtil.java?attredirects=0&d=1

That’s it. Happy Coding..

Saturday, August 22, 2015

Android: Detect when an AdMob ad has loaded (AdListener + network check)

Overview

In some Android apps you need to take action when an AdMob ad successfully loads and a different action when it does not. This post shows how to detect both cases using AdView.setAdListener and how to avoid requesting ads when there is no network connection.

The original examples and links are preserved below, followed by a short checklist and an updated example to match newer Google Mobile Ads SDK patterns.


Detecting ad load with AdListener (original example)

Use AdView.setAdListener and override onAdLoaded() and onAdFailedToLoad(…). This is the code from the original post:

ad.setAdListener(new AdListener() {            
    @Override
    public void onAdLoaded() {
        Log.d(TAG, "Ad Received");
        //Code implementation if the ad is loaded
        ………
        ………
    }

    @Override
    public void onAdFailedToLoad(int errorcode) {
        Log.d(TAG, "Ad Not Loaded Received");
        //Code implementation if the ad is NOT loaded
        ………
        ………
    }
});

Explanation

  • onAdLoaded(): called when the ad has been successfully loaded into the AdView — put the code you want executed on success here (e.g., show the ad container).
  • onAdFailedToLoad(…): called when the ad request failed — put fallback behavior here (e.g., hide the ad container, log the error, schedule a retry).

Note: the snippet above is the original form used in the article. Later SDK versions changed the parameter type for onAdFailedToLoad; see the updated example below.


Check network connectivity before requesting ads

The article recommends checking network status before attempting to fetch ads so the app does not continuously try to fetch when offline. You can use ConnectivityManager as shown in the official Android docs: https://developer.android.com/training/basics/network-ops/managing.html

Original illustrative code from the post:

private static final String DEBUG_TAG = "NetworkStatusExample";
...
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
boolean isWifiConn = networkInfo.isConnected();

networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isMobileConn = networkInfo.isConnected();

Log.d(DEBUG_TAG, "Wifi connected: " + isWifiConn);
Log.d(DEBUG_TAG, "Mobile connected: " + isMobileConn);

The author provided a helper class NetworkUtil; you can download it here: https://sites.google.com/site/karjolblogs/downloads/NetworkUtil.java?attredirects=0&d=1

Use it like this (from the original post):

NetworkUtil net = new NetworkUtil();
int status = net.getConnectivityStatus(getApplicationContext());
if (status != 0) {
    // Code if the network connection is there
    ad.loadAd(new AdRequest.Builder().build());
    ad.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Log.d(TAG, "Ad Received");
            // code when the ad loaded
        }

        @Override
        public void onAdFailedToLoad(int errorcode) {
            Log.d(TAG, "Ad Not Loaded Received");
            // code if the ad loading is failed
        }
    });
} else {
    // Code if the network connection is NOT there
}

Required permission

To check network status at runtime you must have the following permission in AndroidManifest.xml:

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

(Ensure your NetworkUtil implementation relies on this permission.)


Updated notes for newer Google Mobile Ads SDKs

The post originates from 2015; Google Mobile Ads SDK APIs have evolved. Two practical points to add for modern readers:

  • Initialize the Mobile Ads SDK early in your app (for example in Application.onCreate()):
// Example initialization (SDK versions may vary)
MobileAds.initialize(context, initializationStatus -> { /* optional callback */ });
  • In recent SDK versions, onAdFailedToLoad has a different signature and provides richer error information (for example via LoadAdError). Here is an example that shows both an updated listener and how to inspect the error for troubleshooting:
// Updated example (SDK may require different imports; check your SDK docs)
adView = findViewById(R.id.adView);
MobileAds.initialize(this, initializationStatus -> {});
AdRequest adRequest = new AdRequest.Builder().build();

adView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        Log.d(TAG, "Ad Received");
        // show ad view or update UI
    }

    @Override
    public void onAdFailedToLoad(LoadAdError adError) {
        Log.d(TAG, "Ad Not Loaded Received: " + adError.toString());
        // Inspect adError.getCode() or adError.getMessage() for debugging
        // hide ad view or implement retry/backoff
    }
});

adView.loadAd(adRequest);

Refer to the official Google Mobile Ads documentation for the SDK version you use (the original article linked the AdView docs: https://developers.google.com/android/reference/com/google/android/gms/ads/AdView).


Practical tips and recommended behavior

  • Hide the ad container when no ad is available to avoid empty space in your UI.
  • Implement exponential backoff for retries rather than continuous immediate retries.
  • Log errors with enough detail to diagnose (error code/message) but avoid leaking sensitive user data.
  • Ensure you comply with AdMob policies when changing ad behavior.

References and downloads


Final notes

That’s it. Happy Coding..

Friday, August 21, 2015

Integrating Google AdMob Banner Ads in Android (Step‑by‑Step)

I was wondering how to integrate Ads from Google in my Android applications. AdMob is a widely used mobile advertising platform that you can integrate with your Android app fairly easily.

In this post you will learn how to show AdMob banner ads in your Android application. This write‑up is divided into three parts:

  • Getting an Ad Unit ID from the AdMob site
  • Installing Google Play Services in the Android SDK (Eclipse instructions as originally used)
  • Integrating AdSense/AdMob code into your Android app

Note: this article preserves the original Eclipse/SDK Manager workflow used when it was written. Most developers today should use Android Studio and the Google Mobile Ads SDK via Gradle. See the “Modern tooling” note at the end for guidance.

1) Getting Ad Unit Id from the AdMob site

  1. Go to the AdMob site: https://www.google.com/admob/
  2. Create a new account (or log in if you already have one).
  3. Select the “Monetize new app” option.
  4. Search your Android application (from Google Play) or add the app details manually.

AdMob step 1

  1. After filling the app information, AdMob shows setup instructions and lets you create an ad unit and get the Ad Unit ID.

AdMob select app

  1. Your app will be added in AdMob. In the Monetize tab you can select the app, create a banner ad, and copy the Ad Unit ID (it looks like):
ca-app-pub-50xxxx69xxxxxxxx/34xxxxxxxx
  1. You will use this Ad Unit ID in your project later.

2) Installing Google Play Services in Android SDK (Eclipse era instructions)

These steps describe the older Eclipse + SDK Manager workflow used when this post was written.

  1. Open Eclipse and go to Window -> SDK Manager.

SDK Manager

  1. In the packages list select Extras -> check Google Play Services and install it.

Install Google Play Services

  1. Import the Google Play Services project/library into your workspace.
  2. Add the Google Play Services library to the project where you want to integrate AdMob.

Add library to project

3) Integrating AdSense / AdMob code into the Android app

  1. Open your layout XML and add the Ads XML namespace (required to use ads: attributes):
xmlns:ads="http://schemas.android.com/apk/res-auto"
  1. Add an AdView to the layout. Example:
<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="YOUR_AD_UNIT_ID" />
  1. In your Activity Java file initialize the AdView object:
AdView ad = (AdView) findViewById(R.id.adView);
  1. Load an ad from Google:
ad.loadAd(new AdRequest.Builder().build());
  1. Modify AndroidManifest.xml: add required permissions, metadata for Google Play Services, and the AdActivity entry.

Add permissions:

<!-- Used to request banner ads. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Used to avoid sending an ad request if there is no connectivity. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Add Google Play Services metadata (inside ):

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

Add the AdActivity which is required to show ad overlays:

<activity android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

The original article includes a sample manifest; here is the final manifest excerpt reproduced for reference:

xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.marutsoft.sudoku"
    android:versionCode="3"
    android:versionName="1.3">

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19"/>

    <!-- Used to request banner ads. -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Used to avoid sending an ad request if there is no connectivity. -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name="com.marutsoft.sudoku.Splash"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Activity required to show ad overlays. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    </application>

</manifest>

Now run your application and check that the Google ad is shown in the Activity where you have added it. Please note you need to have internet connectivity.

Also you can add code to check the availability of connectivity and then load the ad — we will add that part in my next blog.

That’s it. Happy Coding..


Modern tooling note (recommended)

This article preserves the original Eclipse instructions. If you are using Android Studio (recommended):

  • Use the Google Mobile Ads SDK via Gradle (implementation 'com.google.android.gms:play-services-ads:…') and follow current AdMob docs.
  • Newer SDKs require an application-level AdMob App ID meta‑data entry in AndroidManifest.xml and explicit MobileAds.initialize(…) in your application code before loading ads. Also always use test ads or register test device IDs while developing.

If you want, I can provide a modern, Android Studio + Gradle version of these steps with updated code samples and a short checklist for publishing with AdMob.

Thursday, August 20, 2015

How to Upload and Make a Downloadable ZIP File in Blogger (Using Google Sites)

I wanted to make some files available to download for my readers. Blogger does not provide native attachments, but you can host files elsewhere and link to them from your blog. Below I show how I used Google Sites and the File Cabinet page template to host files and then link to them from a Blogger post.

Quick summary

Host the file on Google Sites using the File Cabinet page template, right-click the Download link to copy the file URL, then paste that URL into your Blogger post as a link (example below).

What you need

  • A Google account
  • A Google Site (create one if you don’t have it)
  • The file(s) you want readers to download (ZIP, PDF, etc.)

Steps

1. Go to Google Sites

Login with your Google account. If you don’t have a Google Site yet, create one using the CREATE button.

2. Create a new site

Choose a template, fill in the site name and location, complete the CAPTCHA if prompted, and click CREATE.

3. Add a new page using the File Cabinet template

Create a new page and select the File Cabinet page template (this template is designed to host downloadable files).

File cabinet template image

4. Upload files

Use the File Cabinet page controls to add the files you want to provide for download.

Upload files image

5. Copy the file link

After uploading, locate the Download link for the file. Right-click the Download link and choose "Copy link address" to copy the direct URL to the file.

Copy link address image

6. Add the link to your Blogger post

In the Blogger post editor, add a link to the text where readers will click to download. You can paste the URL directly using the editor's link tool, or use raw HTML like this:

<a href="PASTE_COPIED_LINK_HERE">Download ZIP</a>

If your editor supports it, select a descriptive anchor text such as "Download ZIP — contains sample code".

7. Publish and test

Publish your Blogger post and click the link to confirm the file downloads correctly. If users report access issues, check the sharing/permission settings on the Google Site (make sure the file/page is publicly accessible if you want anyone to download it).

Helpful screenshots

Create site screenshot

Created file cabinet screen

Notes and alternatives

  • Google Sites UI may change over time — if you cannot find a File Cabinet template, look for a page template that supports file uploads or use another file-hosting service.
  • As an alternative, you can host files in Google Drive or another file host and link to them from Blogger. If you use a different host, be sure to verify public access permissions before publishing.

That’s it. Happy Coding..