0
描述: 每當我的應用程序運行在Android 4.4.4上時,用戶手機的重新啓動速度非常快,並且沒有向Crashlytics發送任何崩潰數據。Android NotificationManager讓手機重新啓動
當我說用戶的手機重新啓動 - 這就像我見過的最快的重新啓動。
應用工作的罰款:
- 4.1.1
- 6.0.1
其他注意事項:
- 我的朋友轉載的bug他4.4.4設備
- 後臺服務創建手機重啓後仍繼續(是的,我用bootReceiver)
- Link to App on Google Play Store
當我刪除下面的「的addAction」代碼時,應用程序正常工作:
public void startNotification(){
final Intent hideNotificationIntent = new Intent(MainActivity.this, HideWallpaperNotificationService.class);
final Intent stopIntent = new Intent(MainActivity.this, StopWallpaperService.class);
final Intent wallpaperCyclerIntent = new Intent(MainActivity.this, MainActivity.class);
alarmIntent = new Intent(this, SetWallpaperService.class);
alarmIntent.putStringArrayListExtra(Constants.PREF_WALLPAPERS, mWallpapers);
PendingIntent nextWallpaperPI = PendingIntent.getService(this.getApplicationContext(), 300, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent stopWallpaperPI = PendingIntent.getService(this.getApplicationContext(), 300, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent showApp = PendingIntent.getActivity(this.getApplicationContext(), 300, wallpaperCyclerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent hideNotification = PendingIntent.getService(this.getApplicationContext(), 300, hideNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//Button
NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(R.drawable.ic_stop_white_18dp, "Stop", stopWallpaperPI).build();
NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(R.drawable.ic_arrow_forward_white_24dp, "Next", nextWallpaperPI).build();
NotificationCompat.Action removeAction = new NotificationCompat.Action.Builder(R.drawable.ic_clear_white_18dp, "Hide", hideNotification).build();
Bitmap original;
if(lastSelected == -1)
original = BitmapFactory.decodeFile(mWallpapers.get(0));
else
original = BitmapFactory.decodeFile(mWallpapers.get(lastSelected));
mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_fit)
.setLargeIcon(original)
.setWhen(0)
.setColor(ContextCompat.getColor(this.getApplicationContext(), R.color.colorPrimary))
.setContentTitle("Wallpaper Cycler")
.setContentText("Click to open")
.setContentIntent(showApp)
.addAction(stopAction)
.addAction(nextAction)
.addAction(removeAction);
notificationManager = (NotificationManager) getSystemService(MainActivity.this.NOTIFICATION_SERVICE);
Notification n;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
n = mBuilder.build();
}else{
n = mBuilder.getNotification();
}
n.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
try{
notificationManager.notify(Constants.NOTIFICATION_ID, n);
}catch(Exception e){Log.e(TAG,"Error notifying");}
}