Skip to content

Instantly share code, notes, and snippets.

@wmbest2
Created May 21, 2010 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmbest2/409204 to your computer and use it in GitHub Desktop.
Save wmbest2/409204 to your computer and use it in GitHub Desktop.
W/System.err(17841): java.lang.Exception: java.lang.Exception
W/System.err(17841): at com.gtalkstatus.android.GTalkStatusApplication.updateConnection(GTalkStatusApplication.java:87)
W/System.err(17841): at com.gtalkstatus.android.GTalkStatusUpdater.onStart(GTalkStatusUpdater.java:123)
W/System.err(17841): at com.gtalkstatus.android.GTalkStatusUpdater.onStartCommand(GTalkStatusUpdater.java:53)
W/System.err(17841): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2873)
W/System.err(17841): at android.app.ActivityThread.access$3500(ActivityThread.java:119)
W/System.err(17841): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
W/System.err(17841): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(17841): at android.os.Looper.loop(Looper.java:123)
W/System.err(17841): at android.app.ActivityThread.main(ActivityThread.java:4363)
W/System.err(17841): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(17841): at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(17841): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
W/System.err(17841): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
W/System.err(17841): at dalvik.system.NativeStart.main(Native Method)
W/System.err(17841): Caused by: java.lang.Exception
W/System.err(17841): at com.gtalkstatus.android.XMPPTransfer.<init>(XMPPTransfer.java:42)
W/System.err(17841): at com.gtalkstatus.android.GTalkStatusApplication.updateConnection(GTalkStatusApplication.java:85)
W/System.err(17841): ... 13 more
D/AndroidRuntime(17841): Shutting down VM
W/dalvikvm(17841): threadid=3: thread exiting with uncaught exception (group=0x4001b198)
E/AndroidRuntime(17841): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(17841): java.lang.RuntimeException: Unable to start service com.gtalkstatus.android.GTalkStatusUpdater@4585fa78
with Intent { act=com.gtalkstatus.android.updaterintent cmp=com.gtalkstatus.android/.GTalkStatusUpdater (has extras) }: java.la
ng.RuntimeException: java.lang.Exception: java.lang.Exception
E/AndroidRuntime(17841): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2882)
E/AndroidRuntime(17841): at android.app.ActivityThread.access$3500(ActivityThread.java:119)
E/AndroidRuntime(17841): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
E/AndroidRuntime(17841): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17841): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(17841): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(17841): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17841): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(17841): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(17841): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(17841): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(17841): Caused by: java.lang.RuntimeException: java.lang.Exception: java.lang.Exception
E/AndroidRuntime(17841): at com.gtalkstatus.android.GTalkStatusUpdater.onStart(GTalkStatusUpdater.java:153)
E/AndroidRuntime(17841): at com.gtalkstatus.android.GTalkStatusUpdater.onStartCommand(GTalkStatusUpdater.java:53)
E/AndroidRuntime(17841): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2873)
E/AndroidRuntime(17841): ... 10 more
E/AndroidRuntime(17841): Caused by: java.lang.Exception: java.lang.Exception
E/AndroidRuntime(17841): at com.gtalkstatus.android.GTalkStatusApplication.updateConnection(GTalkStatusApplication.java:8
7)
E/AndroidRuntime(17841): at com.gtalkstatus.android.GTalkStatusUpdater.onStart(GTalkStatusUpdater.java:123)
E/AndroidRuntime(17841): ... 12 more
E/AndroidRuntime(17841): Caused by: java.lang.Exception
E/AndroidRuntime(17841): at com.gtalkstatus.android.XMPPTransfer.<init>(XMPPTransfer.java:42)
E/AndroidRuntime(17841): at com.gtalkstatus.android.GTalkStatusApplication.updateConnection(GTalkStatusApplication.java:8
5)
E/AndroidRuntime(17841): ... 13 more
public class GTalkStatusNotifier {
static final int WARNING = 0;
static final int ERROR = 1;
static final int SCROBBLE = 2;
static final int CUSTOM = 3;
static final void notify(Context app, int type) {
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
int icon = 0;
String sType = "";
switch(type) {
case ERROR:
icon = android.R.drawable.stat_notify_error;
sType = " - ERROR";
break;
default:
icon = android.R.drawable.stat_notify_error;
}
// Occurs if the connection was never initialized
CharSequence notificationText = "GTalk Status";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, notificationText, when);
CharSequence title = "Music Status" + sType;
CharSequence text = "Music Status was unable to connect to the Google Talk server. Did you enter your username and password correctly?";
Intent notificationIntent = new Intent(app.getApplicationContext(), GTalkStatusActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(app.getApplicationContext(), 0, notificationIntent, 0);
notification.setLatestEventInfo(app.getApplicationContext(), title, text, contentIntent);
mNotificationManager.notify(1, notification);
}
/***************************************************************************
* Copyright 2010 Scott Ferguson *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
package com.gtalkstatus.android;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.Context;
import android.widget.Toast;
import android.app.Service;
import android.os.IBinder;
import android.content.ComponentName;
import android.os.IBinder;
import android.os.Bundle;
import android.util.Log;
import android.app.PendingIntent;
import java.lang.CharSequence;
import java.lang.IllegalStateException;
import java.lang.NullPointerException;
import org.jivesoftware.smack.XMPPException;
import com.android.music.IMediaPlaybackService;
public class GTalkStatusUpdater extends Service {
public static final String LOG_NAME = "GTalkStatusUpdater";
@Override
public void onCreate() {
super.onCreate();
}
public int onStartCommand(Intent aIntent, int aFlags, int aStartId) {
onStart(aIntent, aStartId);
return 2;
}
@Override
public void onStart(Intent aIntent, int aStartId) {
Log.d(LOG_NAME, aIntent.getAction());
if (aIntent.getAction().equals("com.android.music.playbackcomplete")) {
// The song has ended, stop the service
stopSelf();
} else if (aIntent.getAction().equals("com.android.music.playstatechanged")
|| aIntent.getAction().equals("com.android.music.metachanged")
|| aIntent.getAction().equals("com.android.music.queuechanged")) {
bindService(new Intent().setClassName("com.android.music", "com.android.music.MediaPlaybackService"), new ServiceConnection() {
public void onServiceConnected(ComponentName aName, IBinder aService) {
IMediaPlaybackService service = IMediaPlaybackService.Stub.asInterface(aService);
try {
// We disconnect from XMPP if we don't need to keep the connection alive.
// Reconnect if necessary.
if (! GTalkStatusApplication.getInstance().getConnector().isConnected()) {
GTalkStatusApplication.getInstance().updateConnection();
}
String currentTrack = service.getTrackName();
String currentArtist = service.getArtistName();
if (service.isPlaying()) {
String statusMessage = "\u266B " + currentArtist + " - " + currentTrack;
GTalkStatusApplication.getInstance().getConnector().setStatus(statusMessage);
} else {
GTalkStatusApplication.getInstance().getConnector().disconnect();
stopSelf();
}
} catch (IllegalStateException e) {
GTalkStatusNotifier.notify(GTalkStatusApplication.getInstance(), GTalkStatusNotifier.ERROR);
stopSelf();
} catch (NullPointerException e) {
Log.w(LOG_NAME, "Service was never connected!");
GTalkStatusNotifier.notify(GTalkStatusApplication.getInstance(), GTalkStatusNotifier.ERROR);
stopSelf();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
unbindService(this);
}
public void onServiceDisconnected(ComponentName aName) {
GTalkStatusApplication.getInstance().getConnector().setStatus("", 0);
}
}, 0);
} else if (aIntent.getAction().equals("com.gtalkstatus.android.updaterintent")) {
Log.d(LOG_NAME, "Found Generic Intent");
Bundle extras = aIntent.getExtras();
try {
// We disconnect from XMPP if we don't need to keep the connection alive.
// Reconnect if necessary.
if (! GTalkStatusApplication.getInstance().getConnector().isConnected()) {
GTalkStatusApplication.getInstance().updateConnection();
}
String currentTrack = extras.getString("track");
String currentArtist = extras.getString("artist");
Log.d(LOG_NAME, extras.getString("state"));
if (extras.getString("state").equals("is_playing")) {
String statusMessage = "\u266B " + currentArtist + " - " + currentTrack;
GTalkStatusApplication.getInstance().getConnector().setStatus(statusMessage);
} else {
GTalkStatusApplication.getInstance().getConnector().disconnect();
stopSelf();
}
} catch (IllegalStateException e) {
GTalkStatusNotifier.notify(this, GTalkStatusNotifier.ERROR);
stopSelf();
} catch (NullPointerException e) {
Log.w(LOG_NAME, "Service was never connected!");
GTalkStatusNotifier.notify(this, GTalkStatusNotifier.ERROR);
stopSelf();
} catch (XMPPException e) {
Log.w(LOG_NAME, "XMPPException");
GTalkStatusNotifier.notify(this, GTalkStatusNotifier.ERROR);
stopSelf();
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_NAME, e.toString());
throw new RuntimeException(e);
}
}
}
public IBinder onBind(Intent aIntent) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment