happy new year
[adBlock.git] / src / de / ub0r / android / adBlock / HelperAPI5.java
blobbaa58a06ff489dd577dff9058d502a2543e2ab7e
1 /*
2 * Copyright (C) 2010 Felix Bechstein
3 *
4 * This file is part of WebSMS.
5 *
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 3 of the License, or (at your option) any later
9 * version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; If not, see <http://www.gnu.org/licenses/>.
19 package de.ub0r.android.adBlock;
21 import java.lang.reflect.Method;
23 import android.app.Notification;
24 import android.app.Service;
25 import android.util.Log;
27 /**
28 * Helper class to set/unset background for api5 systems.
30 * @author flx
32 public class HelperAPI5 {
33 /** Tag for output. */
34 private static final String TAG = "AdBlock.api5";
36 /** Error message if API5 is not available. */
37 private static final String ERRORMESG = "no API5 available";
39 /**
40 * Check whether API5 is available.
42 * @return true if API5 is available
44 final boolean isAvailable() {
45 try {
46 Method mDebugMethod = Service.class.getMethod("startForeground",
47 new Class[] { Integer.TYPE, Notification.class });
48 /* success, this is a newer device */
49 if (mDebugMethod != null) {
50 return true;
52 } catch (Throwable e) {
53 Log.d(TAG, ERRORMESG, e);
54 throw new VerifyError(ERRORMESG);
56 Log.d(TAG, ERRORMESG);
57 throw new VerifyError(ERRORMESG);
60 /**
61 * Run Service in foreground.
63 * @see Service.startForeground()
64 * @param service
65 * the Service
66 * @param id
67 * notification id
68 * @param notification
69 * notification
71 final void startForeground(final Service service, final int id,
72 final Notification notification) {
73 service.startForeground(id, notification);