mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-01-08 12:18:07 -05:00
IRCService: Use reflection to call setForeground() on old versions.
This commit is contained in:
parent
d4f2c1cc3a
commit
46a45523a8
@ -52,7 +52,7 @@ import android.os.SystemClock;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The background service for managing the irc connections
|
* The background service for managing the irc connections
|
||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class IRCService extends Service
|
public class IRCService extends Service
|
||||||
@ -70,6 +70,8 @@ public class IRCService extends Service
|
|||||||
private static final Class[] mStartForegroundSignature = new Class[] { int.class, Notification.class };
|
private static final Class[] mStartForegroundSignature = new Class[] { int.class, Notification.class };
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private static final Class[] mStopForegroundSignature = new Class[] { boolean.class };
|
private static final Class[] mStopForegroundSignature = new Class[] { boolean.class };
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
private static final Class[] mSetForegroudSignaure = new Class[] { boolean.class };
|
||||||
|
|
||||||
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
||||||
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
||||||
@ -135,7 +137,7 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Settings object
|
* Get Settings object
|
||||||
*
|
*
|
||||||
* @return the settings helper object
|
* @return the settings helper object
|
||||||
*/
|
*/
|
||||||
public Settings getSettings()
|
public Settings getSettings()
|
||||||
@ -156,12 +158,13 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* On start command (Android >= 2.0)
|
* On start command (Android >= 2.0)
|
||||||
*
|
*
|
||||||
* @param intent
|
* @param intent
|
||||||
* @param flags
|
* @param flags
|
||||||
* @param startId
|
* @param startId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId)
|
public int onStartCommand(Intent intent, int flags, int startId)
|
||||||
{
|
{
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
@ -177,7 +180,7 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle command
|
* Handle command
|
||||||
*
|
*
|
||||||
* @param intent
|
* @param intent
|
||||||
*/
|
*/
|
||||||
private void handleCommand(Intent intent)
|
private void handleCommand(Intent intent)
|
||||||
@ -358,7 +361,17 @@ public class IRCService extends Service
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fall back on the old API.
|
// Fall back on the old API.
|
||||||
setForeground(true);
|
try {
|
||||||
|
Method setForeground = getClass().getMethod("setForeground", mSetForegroudSignaure);
|
||||||
|
setForeground.invoke(this, new Object[] { true });
|
||||||
|
} catch (NoSuchMethodException exception) {
|
||||||
|
// Should not happen
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
// Should not happen.
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// Should not happen.
|
||||||
|
}
|
||||||
|
|
||||||
notificationManager.notify(id, notification);
|
notificationManager.notify(id, notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -385,7 +398,17 @@ public class IRCService extends Service
|
|||||||
// Fall back on the old API. Note to cancel BEFORE changing the
|
// Fall back on the old API. Note to cancel BEFORE changing the
|
||||||
// foreground state, since we could be killed at that point.
|
// foreground state, since we could be killed at that point.
|
||||||
notificationManager.cancel(id);
|
notificationManager.cancel(id);
|
||||||
setForeground(false);
|
|
||||||
|
try {
|
||||||
|
Method setForeground = getClass().getMethod("setForeground", mSetForegroudSignaure);
|
||||||
|
setForeground.invoke(this, new Object[] { true });
|
||||||
|
} catch (NoSuchMethodException exception) {
|
||||||
|
// Should not happen
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
// Should not happen.
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// Should not happen.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +515,7 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection for given server
|
* Get connection for given server
|
||||||
*
|
*
|
||||||
* @param serverId
|
* @param serverId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -510,7 +533,7 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the service keep a connection object for this server?
|
* Does the service keep a connection object for this server?
|
||||||
*
|
*
|
||||||
* @return true if there's a connection object, false otherwise
|
* @return true if there's a connection object, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasConnection(int serverId)
|
public boolean hasConnection(int serverId)
|
||||||
@ -593,7 +616,7 @@ public class IRCService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* On Activity binding to this service
|
* On Activity binding to this service
|
||||||
*
|
*
|
||||||
* @param intent
|
* @param intent
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user