Category Archives: android

On this page:

Sleep as Android

Following W-‘s example (I’m such a copycat!), I’ve been trying out a few sleep-related applications on my phone. I get more sleep than he does and my schedule is pretty flexible, but I figure that an app might let me swap out the diminishing returns of sleeping in for some extra discretionary time. For a while, I ran Sleep as Android in parallel with SleepBot, and I also tried each of them separately. I used a sturdy, extra-long USB cable to charge my phone, and I slept with my phone under my pillow.

Both apps seem to agree with each other on the motion they detect, and they also appear to do a decent job of distinguishing between my motion and W-‘s motion (we have different-looking graphs). I’m not sure if there’s a significant difference, but I prefer Sleep as Android’s timing, so I bought it after the trial ended.

I also like Sleep as Android’s way of gradually waking me up with short buzzes, gradually leading up to an audio alarm. I like buzzes because they feel more discreet. I don’t have to feel guilty about interrupting W-‘s sleep.  They also don’t lead to overexposure to whatever tones I picked for my alarm. I’d previously used the built-in Medieval Jaunt and songs like Shonen Knife’s Cookie Day, and those still result in an odd tug on my concentration whenever I hear them.

I’m still not keen on morning meetings, but I can make them with less grumbling now!

Tech report: Living on the T-Mobile 2G network

I was going to be in the US for 14 days, so I picked up a free prepaid SIM card for my phone in order to avoid massive roaming fees. My Samsung Galaxy S3’s compatible with the T-Mobile network, so I opted for the $2 Pay by the Day plan that included unlimited talk, text, and 2G web. A $30 load covered my 14-day trip with a dollar to spare. My parents were going to be there longer, so the $50 unlimited talk/text/web (100MB at 4G speed) was a better fit for them. 

After I put in the SIM card, I confirmed that phone and text worked. The Internet connection wasn’t working, though. The call center agent asked me to make sure airplane mode was off (yup) and packet data was enabled (yup), and she tried resetting my connection to the network. Still no luck, though. Some searching turned up the fact that the 2G network is GSM. The following setting made it possible for me to connect to the Internet using my phone:

Settings > Wireless and networks > More Settings > Mobile networks > Network mode > GSM only

2G was fine for quick map lookups and the occasional web search. I didn’t need to stream video or anything like that, so I didn’t miss the data speeds.

If you’re going to be on a short US trip and you don’t need a lot of data, it might be worth checking this out.

Learning how to tweak my Android devices to fit me

One of the reasons why I like working with the Android operating system is that you can build little tools that interact with the other apps on your system. It’s like the reason why I like Emacs, although Emacs lets you go ahead and redefine routines. Anyway. =)

So here was my motivation: When you share a recipe from the BigOven recipe app, it sends the URL instead of the text. This is inconvenient, so I wanted to make a small tool that extracted the URL and opened it in the browser. That way, I could pass it to Evernote and save the recipe for later searching.

Android stitches different applications together through the idea of an Intent. An application can send an intent to another application in order to get it to do something. It can broadcast an intent to notify other applications that have registered to receive that event. An app can also register to receive various events.

To add something to the Share menu, I needed to write a small application that receives and processes the SEND intent. After trying to figure out if I should use a BroadcastReceiver or a Service or whatever, I settled on using an Activity instead. I might extend this to let me select one of multiple URLs, or recognize phone numbers and things like that too. We’ll see.

Anyway, source. =)

Small steps forward!

Learning more about Android development

From Tuesday: I spent most of the long weekend learning about Android development by working on the MobileOrg for Android open source project. When it comes to learning new technologies, I like working on existing projects more than starting from scratch. There’s plenty of sample code to draw on, and there’s enough functionality to inspire me to think about how to tweak it to fit my needs.

The first two days were really slow in terms of progress. It took me a while to figure out how to build both MobileOrg and MobileOrgNG, and I blogged the instructions in case someone else needs them in the future. After I figured that out, I started fiddling with the settings menu. I made the system more consistent, updated the look and feel to the latest design guidelines, and learned a little more about how everything tied together.

I’m starting to feel more comfortable with Android development. There are still tons of things to learn, of course, but I’m getting the hang of where things are, what things are called, and how things flow together. It’s an amazing thing, feeling the concepts click into place. As you learn more things, the possibilities grow combinatorically.

I should take care of a few other tasks before I move on to the next steps. I have to prepare a presentation for the Quantified Self conference in September. It’ll be an Ignite-style presentation, which is good – clear constraints make it easier to put something together. I also want to do an annual review in preparation for my birthday on Sunday.

After I finish those tasks, what do I want to do next in terms of Android development?

  • I’d like to build a better browsing interface for MobileOrg. I like the way MobileOrgNG makes it easy to browse the Org file’s hierarchy.
  • I want to be able to capture information from other applications.
  • It would be awesome to be able to handle attachments, too.
  • Tasker integration for automatically capturing information, perhaps?
  • Org-contacts would be great.

If I have a year of days like this, I think I’ll be able to learn and do a lot.

How to build MobileOrgNG for Android

MobileOrgNG is kvj’s fork of matburt’s MobileOrg for Android. It has a better layout for large devices and a useful outline view, but doesn’t have some of the other features in the main branch. Here’s how you can build it in Eclipse.

In order to be able to get all the libraries you’ll need, install the Subversive SVN plugin for Eclipse.

  1. In Eclipse, click Help – Install New Software.
  2. Click on the dropdown for Work with and choose the update site for your Eclipse version (ex: Juno).
  3. When the packages load, type in Subversive to filter the list.
  4. Choose Subversive SVN Team Provider. You can choose other plugins as well.
  5. Click Next and proceed through the installation process.

Now you can check out the MobileOrgNG source code and other modules. MobileOrgNG is set up as an Eclipse project, so importing it is easier than importing the original MobileOrg. Here’s how to get MobileOrgNG:

  1. Copy the Git repository URI (ex: git://github.com/kvj/mobileorg-android.git)
  2. In Eclipse, click File – Import – Git – Projects from Git.
  3. Choose URI.
  4. The URI may automatically be detected from the clipboard. If it isn’t, paste it in.
  5. Click Next.
  6. Click Next again.
  7. Click Next.
  8. You should now be at the dialog called Select a wizard to use for importing projects. Choose Import existing projects and click Next.
  9. It should have detected the mobile-org project. Click Finish.

In addition to MobileOrgNG, you will also need the android-actionbar and android-file-dialog libraries. Here’s how to get android-actionbar:

  1. Go to https://github.com/kvj/android-actionbar and copy the Git repository URL (ex: git://github.com/kvj/android-actionbar.git).
  2. In Eclipse, click File – Import – Git – Projects from Git.
  3. Choose URI.
  4. The URI may automatically be detected from the clipboard. If it isn’t, paste it in.
  5. Click Next.
  6. Click Next again.
  7. In the Local destination dialog, change Initial branch to honeycomb-support. Click Next.
  8. You should now be at the dialog called Select a wizard to use for importing projects. Click Cancel.
  9. Click File – Import – Android – Existing Android Code Into Workspace.
  10. Click Browse and choose the android-actionbar directory in your workspace. You can deselect the actionbar example if you wish.
  11. Click Finish.

Here’s how to get android-file-dialog.

  1. Go to http://code.google.com/p/android-file-dialog/source/checkout and copy the SVN URI (ex: http://android-file-dialog.googlecode.com/svn/trunk/).
  2. In Eclipse, click on File – Import – SVN – Project from SVN.
  3. Paste in the URI.
  4. Click Next.
  5. Eclipse should prompt you to normalize the URL. Click Yes.
  6. Click Browse. Choose trunk and click OK.
  7. Click Finish.
  8. Choose Find projects in the children of the selected resource. Click Finish.
  9. Make sure that Check out as a projects into workspace is selected. Click Finish.

Confirm that the libraries are detected.

  1. Right-click on the mobileorg-android project and choose Properties.
  2. Click Android and confirm that both libraries are detected. If not, you may need to remove and re-add them.

The Dropbox API key isn’t part of the source code, so you’ll need to apply for your own at https://www.dropbox.com/developers/start . After you get the API key, add it to your project:

  1. Create a new Android XML Values file. I called mine secrets.xml.
  2. Right-click on the file and choose Team – Ignore.
  3. Add a string with the key dropbox_consumer_key and the value from the Dropbox webpage.
  4. Add another string with the key dropbox_consumer_secret and the value from the Dropbox webpage.

MobileOrgNG should now compile without errors.

Building MobileOrg for Android

If you want to use your Android device to work with your Org-mode files, there’s MobileOrg and there’s MobileOrg NG. MobileOrg seems to have more recent activity and more contributors, but NG has a more tablet-optimized layout and better support for navigating large files, so it would be good to apply some of the ideas from NG to the main MobileOrg project. Might be a useful way for me to learn more about mobile development.

Here’s how to build MobileOrg (the matburt version).

  1. Copy the URI to the Git repository (ex: git://github.com/matburt/mobileorg-android.git).
  2. In Eclipse, click on File – Import – Projects from Git – URI. This may autodetect the URI. If not, paste in the URI. Click Next.
  3. You should now see a list of branches. You can leave them all selected. Click Next.
  4. Check the box for Clone Submodules. This will make sure that the project’s dependencies are also checked out. Click Next.
  5. When you see the dialog called Select a wizard to use for importing projects, click on Cancel.

Because the .project file hasn’t been set up, you’ll need to import the project using a different wizard. However, there’s an Eclipse bug that can make this a bit of a hassle, so this is what you should do to get the projects set up in your system.

  1. Close Eclipse.
  2. Move the mobileorg-android subdirectory from your Eclipse workspace directory to a different directory that is not in your workspace.
  3. Start Eclipse again.
  4. Click on File – Import – Existing Android Code Into Workspace. Click Browse and choose the mobileorg-android folder.
  5. Click on Deselect All.Reselect the following:
    • com.matburt.mobileorg.Gui.OutlineActivity
    • library
    • com.twofortyfouram.locale.MarketActivity
  6. Click on Finish.

Now you should have a bunch of projects in your system. You may need to adjust the libraries and build paths.

  1. Right-click on the com.matburt.mobileorg.Gui.OutlineActivity project and choose Properties.
  2. Click on Android and confirm that both libraries are detected. If not, you may need to remove and re-add them.
  3. Wait for the libraries to be built. If you notice that the compiled JARs don’t have classes, doublecheck that the src folder has loaded the sources. Right-click on the src folder and choose Refresh in order to get the sources recognized by Eclipse.

Re-detect the Git connection by doing the following:

  1. Right-click on the com.matburt.mobileorg.Gui.OutlineActivity project and choose Team – Share Project.
  2. Choose Git.
  3. Check the Use or create repository in parent folder of project.
  4. Check the .git directory you’re using.
  5. Click on Finish.

I also had to remove some code from AndroidManifest.xml because you’re apparently not supposed to have more than one action in an intent-filter:

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 01c4f1e..9fc3eb1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -64,14 +64,11 @@
             android:name=".Gui.OutlineActivity"
             android:label="MobileOrg"
             android:theme="@style/Theme.MobileOrgActionbar" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
-
-                <action android:name="com.matburt.mobileorg.Synchronizer.action.SYNC_UPDATE" />
             </intent-filter>
         </activity>
         <activity
             android:name=".Gui.NodeViewActivity"
             android:label="Org View"

(StackOverflow)

Hope that helps!