Bad notification posted – Couldn’t expand RemoteViews for: StatusBarNotification

For me, the problem was that I was setting a specific height for the root layout, in the custom notification view xml file. As soon as I changed: android:layout_height=”@dimen/notification_expanded” to android:layout_height=”match_parent” in the root layout of notification view, the problem was solved. Also take a look at this example to see a simple example of … Read more

Samsung “App optimisation” feature kills background applications after 3 days

I’ve owned (and currently own) Samsung devices, so I know a little as to how it works from the user’s point of view. The technical specifications and how it works on the inside is an entirely separate issue, and one I can’t answer. The system can detect if you open an app. Samsung uses that … Read more

How to restart service after the app is killed from recent tasks

Override onTaskRemoved() in your service and use alarm manager to start the service again. Below is code from our app that does the same and works fine: @Override public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); Log.d(TAG, “TASK REMOVED”); PendingIntent service = PendingIntent.getService( getApplicationContext(), 1001, new Intent(getApplicationContext(), MyService.class), PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, service); … Read more

How does doze mode affect background/foreground services, with/without partial/full wakelocks?

Processes which have a current running foreground service are supposed to be unaffected by Doze. Bound/unbound, started/not-started, and wakelocks do not affect this whitelisting process. However, there is an issue on Android M devices where foreground services are not properly whitelisted when the foreground service is the in the same process as the top activity … Read more

Control the default music player of android or any other music player

AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if(mAudioManager.isMusicActive()) { Intent i = new Intent(SERVICECMD); i.putExtra(CMDNAME , CMDSTOP ); YourApplicationClass.this.sendBroadcast(i); } you can by getting the audiomanager then sending commands to it. these are the commands. public static final String CMDTOGGLEPAUSE = “togglepause”; public static final String CMDPAUSE = “pause”; public static final String CMDPREVIOUS = “previous”; public … Read more

Debugging a service

Here’s what you can do in four steps: First: In the first interesting method of your service (I used on create): /* (non-Javadoc) * @see android.app.Service#onCreate() */ @Override public void onCreate() { super.onCreate(); //whatever else you have to to here… android.os.Debug.waitForDebugger(); // this line is key } Second: Set break points anywhere after the waitForDebugger … Read more