Android – Adams Bros Blog http://blog.adamsbros.org Fri, 15 Feb 2013 04:36:14 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.2 Upgrade Android SQLite Database http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/ http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/#comments Tue, 28 Feb 2012 20:37:33 +0000 http://blog.adamsbros.org/?p=431 After fiddling with a few different styles of coding a database upgrade implementation for Android, I’ve settled on a fairly simple method.  Basically, I take the old version, and increment a counter until I get to the current version.  Through each iteration, I use switch on the value of the upgradeTo variable, and upgrade each cycle.  If things get too complex for your application, you can always create individual upgrade methods, for each version.

Of course this method will only work if your database version is incremented by one each time you change the database.  And, this really should be the way you version it anyhow.

    public void onUpgrade(
        final SQLiteDatabase db, final int oldVersion,
        final int newVersion)
    {
        int upgradeTo = oldVersion + 1;
        while (upgradeTo <= newVersion)
        {
            switch (upgradeTo)
            {
                case 5:
                    db.execSQL(SQLiteSet.V5_ADD_LAST_CARD);
                    db.execSQL(SQLiteCard.V5_ADD_FAILED);
                    break;
                case 6:
                    db.execSQL(SQLiteSet.V6_ADD_IMPORT_TYPE);
                    break;
                case 7:
                    db.execSQL(SQLiteSet.V7_ADD_SHORT_FNAME);
                    break;
            }
            upgradeTo++;
        }
    }

Someone asked in a comment, why we do the upgrade in a loop.  I do this because I do not know what version they will be converted from or to. So, I must either put a bunch of logic for every possible upgrade variation, such as 1 => 2, 1 => 3, 1=> 4, 3=> 4, etc, etc, or, I can loop through and do one upgrade at a time, and increment the version through each loop.  This GREATLY simplifies the database upgrade.

]]>
http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/feed/ 20
Send Email in your Android Application http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/ http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/#comments Sat, 31 Dec 2011 21:48:59 +0000 http://blog.adamsbros.org/?p=416 I’ve seen a lot of examples of how to send email from an android application.  All of them result in applications coming up in a chooser list that are not appropriate for sending email.  In this post, I’ll described the various solutions I found, and the solution that brings up only email clients.

If you want to skip the junk, and go straight to the solution, go to the last two code snippets at the end.

One variation, from stack overflow, goes something like this.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intent.putExtra(Intent.EXTRA_TEXT   , "body of email");
startActivity(Intent.createChooser(intent, "Send mail..."));

The reason this doesn’t work properly, is because it brings up pretty much any app that can handle text/plain content. To expect a user to send an email with bluetooth, or wifi, or evernote, is simply not appropriate. So, if your intention is to have them send an actual email, as opposed to sharing content in some other way, then this won’t work for you.

Another variation from stack overflow, is to replace the mime-type of text/plain with message/rfc822. This results in a list of applications that can handle “email message” content. As a result, if you have ever-note installed, it comes up in the list as well. It will happily store your complete RFC822 email message for you. However, this is a hack, and is totally not appropriate. That mime type implies that you have already constructed a complete and valid RFC822 email message, including headers and what not.

Finally, I was able to find an example on the IT Wizard website, that shows the almost proper way of doing this, using the mailto URI handling.  Theoretically, only valid email applications will ever come up in this list. It goes like this…

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone@example.com"));
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);

Unfortunately, that only works with gmail on my phone.  So, I revised it to include everything inside the mailto url.

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone@example.com?subject=" +
    Uri.encode("my subject") +  "&body=" +
    Uri.encode("My big long body with spaces, new lines, and all sorts of invalid URI characters"));
startActivity(intent);

Now the only activities that come up are email apps. 😀 Now, if you want the complete list of email applications to always come up for the user, whether they’ve chosen a “default” email app or not, then you need to start the activity like this…

startActivity(Intent.createChooser(intent, "your chooser title"));

I do not know how to attach files to an email, using this method; in fact I do not think it is possible, seeing the mailto: URL scheme is pretty limited.  So, unfortunately, if you want to attach files, you’re going to have to use one of the other methods, with the EXTRA_STREAM option to putExtra() and file URI pointing to a file on your android device.  As a result, you’ll just have to live with some non-email related applications coming up.

If someone has a way of making sure ONLY email apps come up, using the other methods, I’d sure like to hear about it.  Thanks.

]]>
http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/feed/ 9
Conversion to Dalvik format failed with error http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/ http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/#respond Tue, 08 Nov 2011 05:28:58 +0000 http://blog.adamsbros.org/?p=411 I went looking, and looking, and looking, for a solution to this problem. None of them seemed to fit the bill. I tried…

  1. updating proguard
  2. not using libraries I shouldn’t be
  3. re-importing the project
  4. removing duplicate android jars
  5. removing all android jars
  6. a host of other “suggestions” from Eclipse Android users

Not one of the ones I found worked.  I suddenly right clicked the project, and happened to see a menu called “Android Tools“.  I wasn’t thinking it would do anything for my predicament, but was curious what was under it.  I then saw, and clicked, the item called “Fix Project Properties“, and voilà, the error disappeared.

Go figure, an Eclipse option to fix a problem that Eclipse caused.  KEWL!

Hope this helps someone through their pain.

IntelliJ folks, PLEASE add GUI support for android, so that I can ditch this piece of junk Java IDE called Eclipse.

]]>
http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/feed/ 0
Eclipse Android Hello World Tutorial Video – Part 3 http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/ http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/#comments Sat, 23 Jul 2011 03:01:11 +0000 http://blog.adamsbros.org/?p=394 In third part of the android hello world video, we explain the different components of the application, and why things are done in a certain way.  This video is a bit raw.  However, rather than editing the videos, I’m going to try and improve my presentation skills as I go.

Before we get started, the code for part 3 is located on github under the tag “part3“.  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.

git clone git://github.com/TrentonAdams/HelloAndroid.git HelloAndroid
cd HelloAndroid
git checkout part3

In this video, we will

  1. explain the various sections of code
  2. explain the semantics of the android R class for referencing resources
  3. explain the use of localized resource files

We have one new screenshot from this video in the series.  It is the French version of the application.

If this video fails to play, please check back later, it may still be processing.

]]>
http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/feed/ 1
Eclipse Android Hello World Tutorial Video – Part 2 http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/ http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/#comments Sun, 17 Jul 2011 01:05:37 +0000 http://blog.adamsbros.org/?p=368 Part 3 – Code Explained

Okay, I’ve finished another android development demo video.  Sorry it took so long, I got really busy with a new computer and what not, and life in general.  In the next video in this series, I will explain the details of the hello android application.  So, if you do not understand some of what is happening, stay tuned for the next video in the series.

Before we get started, the code for part 2 is located on github under the tag “part2“.  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.

git clone git://github.com/TrentonAdams/HelloAndroid.git HelloAndroid
cd HelloAndroid
git checkout part2

In this video, we do the following…

  1. an actual android application with a button that opens a dialog box. The dialog box has a Okay/Cancel button.
  2. Handling and implementing events
    1. onCreateDialog(int) – when a dialog is requested to be created in this activity, this method is called
    2. onClick(View arg0) – we tied the click event from the button to our activity rather than making a custom class for it
  3. log debug information to the android log
  4. use logcat to see the debug information

Below are the two screens that you will see in this application.

Hello Android Screenshot
Hello Android Okay/Cancel Dialog


This android demo was created using a software package under Linux called “recordMyDesktop”.  It’s terribly slow for encoding the video, which it does after the video has been recorded.  I think it’s recording my whole screen as a series of screenshots, which is probably what takes it so long.  I used it from the command line, as I have not yet attempted to use a GUI tool with it.  I found that I basically required 240 fps, because it did not capture all of my selections if I did not use a high frame rate.  This time I decreased the quality and the bitrate, as it did not seem to make a huge impact on quality.

recordmydesktop –pause-shortcut Control+Shift+P –fps 240 –v_quality 30 –v_bitrate 400 -o ~/Videos/newvideo

This is based in part on the Android Hello World documentation at http://developer.android.com/resources/tutorials/hello-world.html

]]>
http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/feed/ 1
Eclipse Android Hello World Tutorial Video – Part 1 http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/ http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/#respond Thu, 07 Jul 2011 06:22:25 +0000 http://blog.adamsbros.org/?p=341 Part 2

My intention is to make all of my android videos as simple as possible, and as short as possible. That way you can learn what you need to, and get on with it.

This is a quick demo on how to get started on developing for Android.  It is “hopefully” the first in a serious of android demo videos that I will be creating.  I am mainly creating them for myself, so as to become familiar with basic android development tasks, and also to play with recording sessions; I too am a newbie to Android development.  I am putting them on YouTube in case anyone else may find them valuable; perhaps for their simplicity.  I hope you enjoy.

This android demo was created using a software package under Linux called “recordMyDesktop”.  I used it from the command line, as I have not yet attempted to use a GUI tool with it.  I found that I basically required 60 fps, because it did not capture all of my selections if I did not use a high frame rate.

recordmydesktop –fps 60 –v_bitrate 3500 -o helloandroid.ogv

This is based in part on the Android Hello World documentation at http://developer.android.com/resources/tutorials/hello-world.html

]]>
http://blog.adamsbros.org/2011/07/07/eclipse-android-hello-world-tutorial-video-part-1/feed/ 0