Friday, February 26, 2010

Android XMPP

Update: working code for send/receive over XMPP from gtalk / non-gtalk accounts

So, apparently XMPP support was briefly part of the official android SDK, but they took it out again.

There's a respected library called "smack", but it doesn't work with android out of the box.

There's a hack of smack for android called asmack, and that seems to work for me, at least for sending messages.

I haven't figured out how to make it work with talk.google.com, but I created an account at jabber.iitsp.com and was successful in sending an IM from my android.


package com.example.HelloFormStuff;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;

public class HelloFormStuffActivity extends Activity {
public int state = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

XMPPConnection xmpp = new XMPPConnection("jabber.iitsp.com");
try {
xmpp.connect();
xmpp.login("username","password"); // just username, no @ sign
} catch (XMPPException e) {
// TODO Auto-generated catch block
System.out.println("Failed to connect to " + xmpp.getHost());
e.printStackTrace();
}
ChatManager chatmanager = xmpp.getChatManager();
Chat newChat = chatmanager.createChat("destination@example.com", new MessageListener() {
public void processMessage(Chat chat, Message message) {
Toast.makeText(HelloFormStuffActivity.this, message.toString(), Toast.LENGTH_SHORT).show();
}
});

try {
newChat.sendMessage("IMing from my android");
} catch (XMPPException e) {
Toast.makeText(HelloFormStuffActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
...


Don't forget to add the INTERNET permission to the manifest.xml, or you'll get "not connected" exceptions.

Wednesday, February 17, 2010

picasa gdata API and face recognition

Tonight I wanted to download a list of photos from picasaweb with a particular person in them, using the "subjectids" field. I don't see any official way to do this, but here's how I managed it:

In picasaweb (in my web browser), I loaded up the page showing all the photos my friend was in. At the bottom, there was a little "RSS" link. That link looked like this:

http://picasaweb.google.com/data/feed/base/user/credentiality?alt=rss&kind=photo&subjectids=SOME_BIG_LONG_STRING_OF_CHARACTERS&authkey=A_SHORTER_STRING&hl=en_US

I loaded that link in my browser, and it gave me the option to keep it as a live bookmark.

Instead, I trimmed the URL down and plunked it in this little python gdata script:


#!/usr/bin/python

import gdata.photos.service
import gdata.media
import gdata.geo

gd_client = gdata.photos.service.PhotosService()

gd_client.email = 'MY_EMAIL_ADDRESS'
gd_client.password = 'MY_PASSWORD'
gd_client.source = 'exampleCo-exampleApp-1'
gd_client.ProgrammaticLogin()

print "logged in"

photos = gd_client.GetFeed('/data/feed/base/user/credentiality?kind=photo&subjectids=THE_SAME_BIG_LONG_STRING')

for photo in photos.entry:
print photo.content.src


That printed out a list of URLs to the images I wanted.

Thursday, February 11, 2010

TED2010 Jane McGonigal on gamers

Jane puts a really positive spin on the time people spend gaming. Games give us much more positive reinforcement than we get from real life, and people are consequently spending HUGE amounts of time gaming. 500 million gamers worldwide spend at least an hour a day gaming. Serious gamers spend 10,000 hours gaming by the time they turn 21 -- the same time they spent in K-12 education. People have spent 6 million man-years playing World of Warcraft.

I have long felt that we need to find a way to give people in real life the kind of positive stimulus they get in games, and she puts it in a much more optimistic way than I could. I'm really glad she's working on it.

Wednesday, February 10, 2010

#TED Wednesday morning session

Very welcome scientific results on fighting poverty in Africa: handing out a kilogram of lentils with immunizations drasticaly increases rate of child innoculation. Deworming, iron supplements vastly more effective at keeping kids in school than hiring more teachers or other more conventional approaches.

Ukelele flamenco ftw.

And some worthwhile arguments about why our race is evolved to believe things and find patters where there isn't anything, since it's safer to be think there's a lion in the bush and be wrong than to think there isn't and be wrong.

Tuesday, February 09, 2010

Nady USB-1C doesn't get recognized

I couldn't figure out why my Nady USB-1C USB mic didn't get detected in Linux. It showed up in lsusb as 17a0:0001 as it should, but I got errors in dmesg. Turns out it was the passive USB extension I was using with it. Works fine with an active extension.