Skip to content

Commit

Permalink
Adds support for Android O
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitsing committed Sep 10, 2017
1 parent 75babf9 commit 034606e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
minSdkVersion = 16
targetSdkVersion = 25
compileSdkVersion = 25
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = "25.0.2"
VERSION_NAME = "1.0.3"
VERSION_NAME = "1.0.4"
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.singhajit.sherlock.core.investigation;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
Expand All @@ -12,16 +13,35 @@
import com.singhajit.sherlock.R;
import com.singhajit.sherlock.crashes.activity.CrashActivity;

import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;

public class CrashReporter {
private final Context context;
private String CHANNEL_ID = "com.singhajit.com.221B";

public CrashReporter(Context context) {
this.context = context;
}

public void report(CrashViewModel crashViewModel) {
Notification notification = notification(crashViewModel);

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Sherlock",
IMPORTANCE_DEFAULT
);
notificationManager.createNotificationChannel(channel);
}

notificationManager.notify(crashViewModel.getIdentifier(), notification);
}

private Notification notification(CrashViewModel crashViewModel) {
Intent crashActivityIntent = new Intent(context, CrashActivity.class);
crashActivityIntent.putExtra(CrashActivity.CRASH_ID, crashViewModel.getIdentifier());

Expand All @@ -42,7 +62,10 @@ public void report(CrashViewModel crashViewModel) {
notificationBuilder.setColor(ContextCompat.getColor(context, R.color.sherlock_colorAccent));
}

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(crashViewModel.getIdentifier(), notificationBuilder.build());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder.setChannelId(CHANNEL_ID);
}

return notificationBuilder.build();
}
}

0 comments on commit 034606e

Please sign in to comment.