Tips & Tricks: CalendarContract

Hi Android dev’s,

Like most of you already know: We got sauce! or in normal tems, Google released the source of Android 4.0 a.k.a. Ice Cream Sandwich (ICS). For more information see: http://source.android.com/.
This is the first version with code for tablets and phones. And with the source available the carriers and custom rom developers will roll out ICS soon.
That’s why today we will talk about a new feature in the SDK of ICS.

CalendarContract is the Calendar API for Android 4.0 (SDK 14) and up.

CalendarContract provides developers an interface for the calendar URI’s and data columns.

CalendarContract.Calendars:
This table holds the calendar specific information. Each row in this table contains the details for a single calendar, such as the name, color, sync info, etc.
CalendarContract.Events:
This table holds the event specific information. Each row in this table has the info for a single event. It contains information such as event title, location, start time, end time, etc. The event can occur one-time or can recur multiple times. Attendees, reminders, and extended properties are stored on separate tables and reference the _ID to link them with the event.
CalendarContract.Instances:
This table holds the start and end time for occurrences of an event. Each row in this table represents a single occurrence. For one-time events there will be a 1:1 mapping of instances to events. For recurring events, multiple rows will automatically be generated which correspond to multiple occurrences of that event.
CalendarContract.Attendees:
This table holds the event attendee or guest information. Each row represents a single guest of an event. It specifies the type of guest they are and their attendance response for the event.
CalendarContract.Reminders:
This table holds the alert/notification data. Each row represents a single alert for an event. An event can have multiple reminders. The number of reminders per event is specified in MAX_REMINDERS which is set by the Sync Adapter that owns the given calendar. Reminders are specified in minutes before the event and have a type.
CalendarContract.ExtendedProperties:
This table hold opaque data fields used by the sync adapter. The provider takes no action with items in this table except to delete them when their related events are deleted.

Add a new event to the calendar directly:

long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2011, 11, 14, 16, 00);    //year, month, day, hour, minute
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2011, 11, 14, 17, 00);    //year, month, day, hour, minute
endMillis = endTime.getTimeInMillis();
 
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.TITLE, "Ice Cream Sandwich Source Code Release");
values.put(CalendarContract.Events.DESCRIPTION, "Release the ICS source code, so all android followers are happy and will be busy with compiling their custom firmware base on the new source code.");
values.put(CalendarContract.Events.CALENDAR_ID, 3);
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);

For this method you will need the permission: android.permission.READ_CALENDAR, if you don’t want extra permissions in your app, just launch a calendar intent with the event data.

To get a list of all the calendar event, just query Calendar.Events through the ContentResolver.

Regards,
PullesSon – Android

Tips & Tricks: AsyncTask.

Hi Android developers,

This week in tips and tricks: AsyncTask.

A AsyncTask is a class that provides you an easy interface to create a new thread. It is recommended to use it by background tasks, like downloading through a internet connection.
From Honeycomb (SDK API level 11) it’s even mandatory to use Asynctask’s for internet connection downloads and if it’s not done it will force close the application. So it will be also for Ice Cream Sandwich.
Besides it’s mandatory it’s also really handy. You will take pressure from the UI Thread and it will be processed faster and parallel to the UI Thread.

You have to start with:

private class DownloadFilesTask extends AsyncTask<void, void, void>

There are five methods to implement which are:
onPreExecute:
The first method called in the AsyncTask, called on the UI thread. In this method you usually prepare the progressbar, if needed.

@Override
protected void onPreExecute() {
    super.onPreExecute();
    showDialog(DIALOG_DOWNLOAD_PROGRESS);
}

doInBackground:
This is the method where is all the action. This method executes the time consuming tasks and publish the task progress, executed in background thread.

@Override
protected String doInBackground(String... params) {
    // perform Long time consuming operation
    return null;
}

onProgressUpdate
Method that updates the progress of the AsyncTask, run on the UI thread. This is where you update the progressbar.

@Override
protected void onProgressUpdate(String... progress) {
    mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}

onPostExecute
The final method that gets called after doInBackground finishes, here we can update the UI with the results of the AsyncTask, like removing the progressbar.

@Override
protected void onPostExecute(String unused) {
    try {
        dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
    } catch (Exception e){
        Log.e("APP_NAME","Unknown exception caught: " + e.getMessage());
    }
}

onCancelled
This method gets called if the AsyncTask.cancel() methods is called, terminating the execution of the AsyncTask.

@Override
protected void onCancelled() {
    dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}

To execute it just use:

new DownloadFilesTask().execute(param1, param2);

As you can see the AsyncTask is easy to implement and the methods are really easy to use and understand. It is highly recommended to use AsyncTask for task that doesn’t have to update the UI Thread.

We use AsyncTask in Let Me Android That For You and Perka’s File Stash.

For more information: http://developer.android.com/reference/android/os/AsyncTask.html

Regards,
PullesSon – Android

Let Me Android That For You – Update

Hi all,

Let Me Android That For You is updated and you can now add your own Bit.Ly userid and API key. Press the menu button and then: Change Bitly settings.

This new version is now available in the market.

Regards,
PullesSon – Android

Tips and Tricks from PullesSon Android

Hi Android developers,

Starting from today we are going to (try to) blog every week some tips and tricks from our team.

The previous post about the ads can be seen as the tips and tricks for this week, but for this first post we will try to add some more information resources and the next tips and tricks will be more detailed into the code.

Websites:
Android Developers
Stack Overflow
Android Developers Google Group
Google Code Android project hosting

IRC (Internet Relay Chat):
Android Developers IRC

SDK on PC:
path-to-sdk-directory/samples/android-{sdk-version}/
path-to-sdk-directory/extras/android/compatibility/v4 or v13

And of course a good source is: Google, to search for example codes and tutorials.

Regards,
PullesSon Android

From AdMob to MobClix

Hi Android-friends,

Yesterday we decided to go from AdMob to MobClix.
In the past we had several issues with AdMob and then like a a few months ago our account was blocked, due to fraud. We don’t do fraud so we opened an issues on their website.

First of all we noticed that the website to open an issue is almost impossible to find and with some hours of looking through support pages we found the form to submit an issue. It was a half-baked form, no stylesheets, questions with half the answers and above all pointed to AdSense and not AdMob. We filled it out the best we could and we got a thank you page and a confirmation email.

Then we waited like a month and no response from AdMob, neither from AdSense, neither from Google.

So we started searching for a contact email, again searching for hours on the support pages and we found an AdSense and AdMob contact email. We decided to forward the confirmation email to both of the contact emails. Like a month later we found an email from AdSense in our inbox, if we could provide our login, so we did and all they answered was: We can’t find it in our system. And no word from AdMob. So sad to hear a Google company let us down.

That was why we started to look for an alternative, we found several, had some comparisons and decided to use MobClix. It is even more simple to implement as AdMob and all campaigns are based per app, so you can choose the ads providers on application level. Besides they use PayPal for their payments, which makes it easier for most of the people.

All are apps with ads: Call Restrictor Free and Let Me Android That For You are updated with the new ads, they look nicer as AdMob and the implementation tooks us like 10 minutes (including removing the AdMob code).
Also in the first 24h on Mobclix we have earned more then we did in 3 months with AdMob.

So F U AdMob and welcome MobClix.

Regards,
PullesSon Android

Perka’s File Stash – update

Perka’s File Stash is updated with the: Flash zip option to flash CWM zips.
Long press on the zip file -> choose: Flash zip -> Wait untill it’s downloaded -> confirm the flash, if the file is already downloaded, just confirm the flash.

Less updates

Lately there were not much updates on the site, but we are really busy to get some of the new apps finished and getting a hold on OpenGL ES 2.0. So keep your phones and tablets ready for a new load of apps from PullesSon which are to be announced soon.

Android market link for Developer PullesSon

Find all our applications by clicking the following image:

Available in Android Market

Honeycomb and Tegra 2

We are currently working on some Honeycomb (Android 3.x) project with Nvidia Tegra 2. So expect some BIG applications in the near future.

LMATFY is updated

Hi all.

LMATFY is just updated with a widget. The widget works like a shortcut, because their is no way to add a inputbox to a widget. It will be updated when it’s available.

The code is ready for the input box, only the Android OS doesn’t support it (yet).

Greetings,
Niek
PullesSon – Android