2 * Copyright (C) 2010 Felix Bechstein
4 * This file is part of WebSMS.
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
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
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
;
28 * Helper class to set/unset background for api5 systems.
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";
40 * Check whether API5 is available.
42 * @return true if API5 is available
44 final boolean isAvailable() {
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) {
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
);
61 * Run Service in foreground.
63 * @see Service.startForeground()
71 final void startForeground(final Service service
, final int id
,
72 final Notification notification
) {
73 service
.startForeground(id
, notification
);