diff options
author | Hans Nielsen <agenthh@gmail.com> | 2011-05-13 21:38:05 -0700 |
---|---|---|
committer | Hans Nielsen <agenthh@gmail.com> | 2011-05-13 22:46:02 -0700 |
commit | 8f96a63ebeae772fb4eee5e80cc5b64b88df0c2d (patch) | |
tree | 05f8ab6446cb54fd8b6079c88a254fde1fd40dcf /src | |
parent | a01873bb26e017fda36011255a3460b8021f4bd6 (diff) | |
download | connectbot-8f96a63ebeae772fb4eee5e80cc5b64b88df0c2d.tar.gz connectbot-8f96a63ebeae772fb4eee5e80cc5b64b88df0c2d.tar.bz2 connectbot-8f96a63ebeae772fb4eee5e80cc5b64b88df0c2d.zip |
Use method invoke to work around SetForeground not being in API 11+
Diffstat (limited to 'src')
-rw-r--r-- | src/org/connectbot/service/ConnectionNotifier.java | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/org/connectbot/service/ConnectionNotifier.java b/src/org/connectbot/service/ConnectionNotifier.java index a9c054d..ffe2230 100644 --- a/src/org/connectbot/service/ConnectionNotifier.java +++ b/src/org/connectbot/service/ConnectionNotifier.java @@ -17,6 +17,9 @@ package org.connectbot.service; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import org.connectbot.ConsoleActivity; import org.connectbot.R; import org.connectbot.bean.HostBean; @@ -128,19 +131,41 @@ public abstract class ConnectionNotifier { public abstract void hideRunningNotification(Service context); private static class PreEclair extends ConnectionNotifier { + private static final Class<?>[] setForegroundSignature = new Class[] {boolean.class}; + private Method setForeground = null; + private static class Holder { private static final PreEclair sInstance = new PreEclair(); } + public PreEclair() { + try { + setForeground = Service.class.getMethod("setForeground", setForegroundSignature); + } catch (Exception e) { + } + } + @Override public void showRunningNotification(Service context) { - context.setForeground(true); + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.TRUE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } getNotificationManager(context).notify(ONLINE_NOTIFICATION, newRunningNotification(context)); } @Override public void hideRunningNotification(Service context) { - context.setForeground(false); + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.FALSE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } getNotificationManager(context).cancel(ONLINE_NOTIFICATION); } } |