Hack to hide a notification
Этот коммит содержится в:
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
<service android:name=".TrackingService" />
|
<service android:name=".TrackingService" />
|
||||||
|
|
||||||
|
<service android:name=".TrackingService$HideNotificationService" />
|
||||||
|
|
||||||
<receiver android:name=".AutostartReceiver">
|
<receiver android:name=".AutostartReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
|||||||
public static final String KEY_INTERVAL = "interval";
|
public static final String KEY_INTERVAL = "interval";
|
||||||
public static final String KEY_PROVIDER = "provider";
|
public static final String KEY_PROVIDER = "provider";
|
||||||
public static final String KEY_STATUS = "status";
|
public static final String KEY_STATUS = "status";
|
||||||
public static final String KEY_FOREGROUND = "foreground";
|
|
||||||
|
|
||||||
private static final int PERMISSIONS_REQUEST_DEVICE = 1;
|
private static final int PERMISSIONS_REQUEST_DEVICE = 1;
|
||||||
private static final int PERMISSIONS_REQUEST_LOCATION = 2;
|
private static final int PERMISSIONS_REQUEST_LOCATION = 2;
|
||||||
@@ -105,7 +104,6 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
|||||||
preferenceScreen.findPreference(KEY_PORT).setEnabled(enabled);
|
preferenceScreen.findPreference(KEY_PORT).setEnabled(enabled);
|
||||||
preferenceScreen.findPreference(KEY_INTERVAL).setEnabled(enabled);
|
preferenceScreen.findPreference(KEY_INTERVAL).setEnabled(enabled);
|
||||||
preferenceScreen.findPreference(KEY_PROVIDER).setEnabled(enabled);
|
preferenceScreen.findPreference(KEY_PROVIDER).setEnabled(enabled);
|
||||||
preferenceScreen.findPreference(KEY_FOREGROUND).setEnabled(enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -36,9 +36,45 @@ public class TrackingService extends Service {
|
|||||||
|
|
||||||
private TrackingController trackingController;
|
private TrackingController trackingController;
|
||||||
|
|
||||||
private boolean foreground;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
private static Notification createNotification(Context context) {
|
||||||
|
Intent notificationIntent = new Intent(context, MainActivity.class);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
|
||||||
|
|
||||||
|
Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0);
|
||||||
|
try {
|
||||||
|
Method method = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
|
||||||
|
try {
|
||||||
|
method.invoke(notification, context, context.getString(R.string.app_name), context.getString(R.string.settings_status_on_summary), pendingIntent);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
|
} catch (SecurityException | NoSuchMethodException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
notification.priority = Notification.PRIORITY_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HideNotificationService extends Service {
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.ECLAIR)
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
startForeground(NOTIFICATION_ID, createNotification(this));
|
||||||
|
stopForeground(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Log.i(TAG, "service create");
|
Log.i(TAG, "service create");
|
||||||
@@ -47,33 +83,9 @@ public class TrackingService extends Service {
|
|||||||
trackingController = new TrackingController(this);
|
trackingController = new TrackingController(this);
|
||||||
trackingController.start();
|
trackingController.start();
|
||||||
|
|
||||||
foreground = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(MainActivity.KEY_FOREGROUND, false);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
|
||||||
|
startForeground(NOTIFICATION_ID, createNotification(this));
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR && foreground) {
|
startService(new Intent(this, HideNotificationService.class));
|
||||||
Intent notificationIntent = new Intent(this, MainActivity.class);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
|
||||||
|
|
||||||
Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0);
|
|
||||||
try {
|
|
||||||
Method method = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
|
|
||||||
try {
|
|
||||||
method.invoke(notification, this, getString(R.string.app_name), getString(R.string.settings_status_on_summary), pendingIntent);
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
|
|
||||||
Log.w(TAG, e);
|
|
||||||
}
|
|
||||||
} catch (SecurityException | NoSuchMethodException e) {
|
|
||||||
Log.w(TAG, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
int notificationId = NOTIFICATION_ID;
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
||||||
notification.priority = Notification.PRIORITY_MIN;
|
|
||||||
} else {
|
|
||||||
notificationId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
startForeground(notificationId, notification);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +114,7 @@ public class TrackingService extends Service {
|
|||||||
Log.i(TAG, "service destroy");
|
Log.i(TAG, "service destroy");
|
||||||
StatusActivity.addMessage(getString(R.string.status_service_destroy));
|
StatusActivity.addMessage(getString(R.string.status_service_destroy));
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR && foreground) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,4 @@
|
|||||||
android:summary="@string/settings_provider_summary"
|
android:summary="@string/settings_provider_summary"
|
||||||
android:title="@string/settings_provider_title" />
|
android:title="@string/settings_provider_title" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="foreground"
|
|
||||||
android:summary="@string/settings_foreground_summary"
|
|
||||||
android:title="@string/settings_foreground_title" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -40,10 +40,4 @@
|
|||||||
android:summary="@string/settings_provider_summary"
|
android:summary="@string/settings_provider_summary"
|
||||||
android:title="@string/settings_provider_title" />
|
android:title="@string/settings_provider_title" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="foreground"
|
|
||||||
android:summary="@string/settings_foreground_summary"
|
|
||||||
android:title="@string/settings_foreground_title" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user