Jul
28

Pro Android Augmented Reality

So there’s been a recent barrage of comments requesting for a link to buying the book, so I’m going to put the info in a post, rather than replying to each comment individually. The book is available in both print and eBook formats.

Print from Amazon.com

Kindle Edition from Amazon.com

Print on Flipkart.com

 

Permanent link to this article: http://www.appaholics.in/pro-android-augmented-reality/

Feb
09

Setting Up A BlackBerry Development Environment On A Mac

I recently decided to go into BlackBerry development. One of the biggest challenges has been to get all of the necessary tools working on my MacBook Pro, as Mac support from RIM is recent and quite buggy. In this post, I will show you how to setup your Mac to write BlackBerry apps.

To start with, point a tab in your browser to https://bdsc.webapps.blackberry.com/java/download/eclipse?os=mac and download the full Eclipse + Plugin installer. This is a large download (~350MB) and will take a while to complete. After downloading it, run the installer to finish the installation.

Now read through the entire page to see what RIM recommends you do next, and carefully proceed to ignore it. The installer you ran will only give you the 7.0 Platform SDK. if you want to target a larger audience, you will want to install the other SDKs as well. The method using the update site given on that page will not work, as that update site no longer exists, and RIM has failed to update the instructions.

Instead, follow the instructions I give you here. In Eclipse, go to Help -> Install New Software. In the box that opens, click the Add… button and add a site with any name you like and the following URL: http://www.blackberry.com/go/eclipseUpdate/3.6/java.

Once you add it, a list of software should come in the box below it. Select all of the platform levels you want to install and start the install process. All of them have relatively large downloads, so wait for some time. Once all of them have installed, you will realize that this is all Windows software. Now don’t panic. Do the following to get it working on your Mac:

Start the process of creating a new BlackBerry project and then click the configure JREs link in the JRE part.

Configure JREs

Now open the finder, and navigate to the location of your Eclipse install. Go to the Plugins folder, and locate the folder with the SDK you want to add. It should have a name like net.rim.ejde…, with the version of the SDK given in it. Open the components folder and then open the BlackBerry.ee file in your favorite text editor. Now replace some of the lines with their counterparts that I give below:

-Dee.executable=${ee.home}/simulator/fledge.exe
-Dee.bootclasspath=${ee.home}/lib/net_rim_api.jar
-Dee.javadoc=file:${ee.home}/docs/api
-Dee.language.level=1.3
-Djava.home=${ee.home}

Save the file. Now replace the components/bin folder with the one in the 7.0 SDK’s components folder. Now go back to the JRE management dialog in Eclipse and Click add JRE. Select the BlackBerry.ee file you edited and click Finish.

Your new SDK is now ready. Repeat these steps until all of your SDKS have been setup.

Permanent link to this article: http://www.appaholics.in/setting-up-a-blackberry-development-environment-on-a-mac/

Oct
01

Source code on Git

I have created a Git repository which will be updated with all the tutorials’ source code. The code will be a complete project which can be run directly.

The Android repository can be found here.

I will add the code for the previous tutorials as well.

Permanent link to this article: http://www.appaholics.in/source-code-on-git/

Aug
30

MTP, External Storage, and Your App

Guest post by Mark Murphy

Some changes in Android 3.x may impact your application, if you are
writing content to external storage and want users to be able to access
those files on their desktops or notebooks.

Android 3.0 switched the means by which users mount external storage
and make it available to their desktop or notebook. Previously, Android
used USB Mass Storage Mode, the same protocol used by USB thumb
drives and the like. This is why when the external storage was unavailable
when a host machine had it mounted —; USB Mass Storage Mode was not
designed for intelligent storage devices.

Android 3.0 now uses the Media Transfer Protocol as the way external storage
gets mounted. Much of what has been written about this has focused on the
user experience, such as needing third-party software to use MTP on OS X
and Linux.

However, there is a more subtle shift that is important to developers: the
MTP contents are *not* based on the literal contents of external storage.
Instead, MTP contents are based on what files have been scanned by
`MediaScannerConnection`. If you write a file to external storage, until and
unless that file is scanned by `MediaScannerConnection`, it will not be
visible to users over MTP.

External storage is scanned on a reboot and possibly on a periodic basis.
Users can manually force a scan via utilities like SDRescan. However,
the best answer is for you to use `scanFile()` on `MediaScannerConnection`
to update the media database after you close your file. This will make your file
immediately available to the user.

Previously, we only needed `MediaScannerConnection` for actual “media”, such
as MP3 files or MP4 videos. Now, we need it for everything, if we want to give
the user immediate results.

On a related note, it may be that Android 3.0 or 3.1 would filter MTP and not
show the contents of directories that contain `.nomedia` files, applying the
same rules that filter those out of things like the Music app. By Android 3.2
—; at least based on light testing with the XOOM —; that filtering
has been lifted. MTP shows everything, while `.nomedia` still filters out
content from installed media-consuming applications.

Permanent link to this article: http://www.appaholics.in/mtp-external-storage-and-your-app/

Aug
26

Introducing… Me! The new guy.

Hi everyone! I’m Mark, and I make Android apps, run Linux, and do all kinds of other tech-related stuffs. Right now I’m writing a huge article on setting up an Android development environment which should be done by this weekend. I hope to make additional contributions in the future, so look forward to somewhat more frequent tutorials and guides soon.

Permanent link to this article: http://www.appaholics.in/introducing-me-the-new-guy/

Aug
22

Installing, Updating and Uninstalling apps

This tutorial is in response to a few things. For one, somebody left a comment on one of my apps saying that they couldn’t uninstall it. Now my apps are not shipped with the ROMs as bloatware and it is unlikely that it randomly got installed at such a low level that the user can not uninstall it. The only explanation was that the user doesn’t know how to uninstall it. Another reason for writing this is a thread on the android-developers list about users not updating the app.

Installing

There are essentially two ways for the user to install an app. Developers use another method which your average user will not use.

The most common and obvious method is to use the Android Market. This is an official Google app that is pre-installed on all devices running Android that are approved by Google. There are of course ways to install the Market on ROMs like Cyanogen but that is for another day. To install an app from the Market you can search for it on the desktop or the mobile version, click install and accept the permissions required.

Another method, commonly known as side loading, is to, well, side load apps on your device. This is the method used by alternate markets such as Amazon. Do this this you have to enable “Unknown Sources” in Settings -> Applications. After that it is simply a matter of getting the apk to your device and letting the package manager install it. There are some disadvantages to this method. You do not get update notifications if a new version of the app is available, unless the developer has written a notifier into the app itself.

We will not discuss the third method as that will be part of another tutorial aimed at developers.

Updating

You would be surprised at how many users don’t know how to, or don’t update the apps on their device. I still get a few error reports every day for bugs that were fixed six updates ago!!

The Android Market makes updating very very easy. When you are connected to the internet the Market will check your apps and the notify you if there is an update. The all you need to do is go to “My Apps” and update all the apps that need to be updated.

If you side loaded the apps you may need to regularly check for updates.

Uninstalling

Uninstalling apps is even simpler than installing them, in my opinion. Basically all you need to do is go to Settings -> Applications -> Manage applications. Then select the app you want to uninstall from the list and click the Uninstall button.

Permanent link to this article: http://www.appaholics.in/installing-updating-and-uninstalling-apps/

Aug
18

Running a task with a delay

There will be times when you want to run something after a delay. Say, you have a time delay camera app for taking group photos. You will have the user click the shoot button and the have a delay to let the user get into the photo. In situations like this you can use any of the two following methods.

Using a Timer

Let us look at the Timer method first. The Timer is part of the standard java as well so some of you may already be familiar with it. To declare a Timer all you need to do is put in the following line:

Timer updateTimer = new Timer("timerName");

This will raise an exception if you leave the part where I have written timerName empty. Now you have finished creating a Timer object with the name updateTimer. After this you need to add the delay and code to run. This is done easily like this:

updateTimer.scheduleAtFixedRate(new TimerTask() {
        	public void run(){
        		//Your code goes here
        	}
        }, 0, 1000);

Here you can also call a function instead of putting the code directly. The 0 in the end is the time to delay before first execution. 1000 is the time to delay before subsequent executions.Both time are in milliseconds.

Using a Runnable

This does exactly the same thing as the previous option, but it is entirely Android. Using a Runnable is as easy as using a Timer. You start by declaring a Handler at the head of your Activity so that you can access it in any method. Use the following line. you can replace the “handler” with any word you like.

public Handler handler;

Now assign a new Handler to you handler in your app’s onCreate:

handler=new Handler();

After this you create a Runnable in any method you like.

final Runnable r = new Runnable()
        {
            public void run()
            {
            	handler.postDelayed(this, 1000);
            	//Your code
            }
        };
    	handler.postDelayed(r, 1000);

Now let us go through the code. In the first line you declare a new Runnable called “r”.  The you run the “run()” method of this Runnable. Line 5 tells Android to delay the next execution by 1000 milliseconds. The next two are just closing brackets. Finally the last line tells Android to run it the first time.

That’s it!

Permanent link to this article: http://www.appaholics.in/running-a-task-with-a-delay/

Aug
16

Marketing your apps with $0

There are more than a few hundred small developers who can not afford thousands of dollars in advertising their apps. This reduces the awareness about their apps, leading to fewer downloads. Due to this they forever remain small, barely known developers. Here I list in detail a few ways to market your app without spending any money.

1) Posting it on mailing lists is very helpful. Often on the better lists there are thousands of developers who would be happy to try it out. You also get constructive feedback from them which can help you improve the app by great margins. You should however note that if you don’t choose a mailing list wisely it will be worse as you would be regarded as a spammer. Generally spammers don’t go very far in this world. An example of a usable mailing list is the Android Discuss.

2) Post the link to your app in popular forums. Most such forums have a dedicated section for app announcements. Several people will view it here as well, ad you are less likely to be regarded as a spammer. It is also very helpful to include QR Codes with the links so that it may easily be downloaded on a mobile device. A nice forum to start is Android Forums.

3) Include a link in your email signature to a few of your apps or a page that has QR Codes and links to all of them. This is quite effective as mailing lists are often archived on many sites and those conversations turn up in Google searches, where a user might click on your links. However, you should use the page linking method if you have a lot of apps. If someone sees to many links in your signature they are likely to ignore it.

4) Don’t limit yourself to one distribution system. While the Android Market may be the most popular way to distribute apps it doesn’t mean that it is the only way. You should also put up your apps on the Amazon Market or Soc.io Mall.

5) People often download apps with good ratings. Gather all your friends with Android Devices and have a rating party. That is, get them all to give you five stars and positive comments. This itself could make a huge difference.

6) Get featured on the various markets. If this happens to you then your app will be displayed to every user who opens the market on the front page. This increases installs by an absolutely tremendous amount. Exactly what formula is used at the Android Market is a bit of a mystery, but it seems to be a combination of good ratings and steady downloads.

That is all I can think of right now. If you have any other method just pop in a comment or mail me from the contact form on the left.

Permanent link to this article: http://www.appaholics.in/marketing-your-apps-with-0/

Aug
15

Let’s take a Screenshot

Let us assume you have made an Android app. Now you want to upload it to the Android Market. You have typed out the description, uploaded the apk, added the app icon, added the high res graphics, given it a category and you click submit. Suddenly in red you are told to add at least two screenshots. Now where do you get those from? A lot of people say that you need a rooted device for those and you may not have one. Heck, you may not even have a device and would have been using the emulator (BTW if you have been using the emulator only it is a very bad idea). Now you shall finally know how to take the screenshots you need, whether you are on a device or an emulator.

Let us start with screenshots on the emulator. First of all you will need to get the “Devices” tab to show. All you need to do is go to Window -> Show View -> Other. In the dialog box that pops up expand Android and select Devices. Make sure that USB Debugging is enabled on your device. If not go to Settings -> Applications ->Development -> USB Debugging. This may vary in location from ROM to ROM. Now next the the LogCat tab there will be one that reads Devices. Now when you want to take the screenshot click the button shown below:  On some versions of the dev tools this might look a bit like a picture. To find it just hover over each button until “Screen Capture” pops up.

Let us move on to the phone now. You can use the method shown above as well by connecting your device. There are however simpler ways. I will now tell you about two apps that allow you to take screenshots. The likelihood of these working depends on your phone manufacturer and how much freedom they give you. They will certainly work on rooted devices. The apps are Screenshot It and ShootMe. Just install them, set your preferences and use them!! Comment with success or failure of these apps with your device name, Android version, and whether it is rooted or not to help others.

UPDATE: On Honeycomb it is possible to take a screenshot by going to the Screen section in settings. If you check the checkbox titled “Screenshot” and then long press the recent apps button to take a screenshot. Thanks Mark.

Permanent link to this article: http://www.appaholics.in/lets-take-a-screenshot/

Aug
14

Using the LogCat

If any of you subscribe to the Android Developers mailing list you will often find people who post hundreds of lines of code saying that there is a problem, and asking for help. Now, this list is a community where developers like me take their own time out to help people. We are not paid to do so and it would be unlikely that anyone would spend time reading all that code. Mostly we would be more than happy to help if the person posting the question includes the relevant part of the LogCat and the code lines it mentions, perhaps pasting the entire method of that error line. This tutorial explains the LogCat, how to use it and find the relevant parts of the code and some of the most common errors displayed in the LogCat.

First of all let us look at looking at the LogCat. In the top right corner of your eclipse there will be two tabs. These will be “Java” and “Debug”. Click on the Debug tab. In all probability you will see two columns there. One will have “Console” and “Tasks” tabs and the other will have just one tab reading “LogCat”. If the LogCat one is not visible then go to Window -> Show View -> LogCat. Now start your debug run. After the emulator or device as loaded to a certain extent you should see something like this in the LogCat:

Nice and colorful isn’t it?

Your errors will be marked in red and generally be a block. See the example below. (The errors from your app will probably be around 10-20 lines)

These errors are what you need to post to lists and friends to get help.

Let us talk about filtering the LogCat. It is huge in size and it will often be a pain to go through all of it. There are four buttons on top that look like this: The first button “V” stands for verbose and will display everything. The second one “D” stands for debug and will display all the messages that can be useful for debugging. Clicking this may not seem to change anything but it does, trust me on that. The third one “I” is info. It will display all the Information text, generally the errors, warnings and, well, info messages. The fourth one “W” is warnings. This will display only errors and warnings. The fifth and last one “E” is for errors. This will display only errors. Another way to filter it is to type something into the message text box below. There are a few more options that can be utilized only from the command line. The table below from Google covers all the options pretty well.

Option Description
-b <buffer> Loads an alternate log buffer for viewing, such as event or
radio. The main buffer is used by default. See Viewing Alternative Log Buffers.
-c Clears (flushes) the entire log and exits.
-d Dumps the log to the screen and exits.
-f <filename> Writes log message output to <filename>. The default is
stdout.
-g Prints the size of the specified log buffer and exits.
-n <count> Sets the maximum number of rotated logs to <count>. The default value
is 4. Requires the -r option.
-r <kbytes> Rotates the log file every <kbytes> of output. The default value is
16. Requires the -f option.
-s Sets the default filter spec to silent.
-v <format> Sets the output format for log messages. The default is brief format. For a
list of supported formats, see Controlling Log Output
Format
.

Now it is time for you to understand the LogCat. This is very easy but utilizing the information you gain can be very difficult. Let us start with the exception I have encountered most commonly. The NullPointerException. It looks something like the screenshot below.

This is most often caused if

1) Your variable does not exist
2) The variable has a null value when it should not be containing null.

The most important part comes after the Caused by line. Somewhere here you will see you package name and a pointer to the line on which the error occurred. Now you can go to that line and see what could possibly be null.

Let us move on to another error. The StackOverflowError. Sadly I couldn’t cause one on demand and so don’t have a screenshot. Anyways this error occurs when your app exceeds the stack limit of the device or emulator. This mostly happens if you get stuck in an infinite loop.It can also happen in a correctly written but deeply recursive program. The only way to solve it is to utilize less resources.

I can’t think of any other common errors right now but if you want me to elaborate on any other one then comment with the error name.

Acknowledgments: Thanks to Kristopher Micinski for bringing to my attention a few missing options. Table added as a result.

Permanent link to this article: http://www.appaholics.in/using-the-logcat/

Older posts «