diff --git a/app/build.gradle b/app/build.gradle index 8a5b3fa..f34f8ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ compileSdkVersion 28 defaultConfig { applicationId "com.example.cosmosclient" - minSdkVersion 15 + minSdkVersion 26 targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java b/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java index d6d0834..74be9d2 100644 --- a/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java +++ b/app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java @@ -63,6 +63,7 @@ private CosmosLocation LOC = new CosmosLocation(); private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定 private int count = 0; + private NotificationManager notificationManager; public CosmosBackgroundService() { super("CosmosBackgroundService"); @@ -82,6 +83,10 @@ context = getApplicationContext(); // LocationManager インスタンス生成 locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); + notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); + int importance = NotificationManager.IMPORTANCE_HIGH; + NotificationChannel mChannel = new NotificationChannel("cosmos", "cosmosChannel", importance); + notificationManager.createNotificationChannel(mChannel); } @Override @@ -249,6 +254,28 @@ updateAreaInformation(location); this.notifications=searchNotifications(cosmos,location); + sendNotifications(this, notifications); + + + } + + private void sendNotifications(CosmosBackgroundService cosmosBackgroundService, List notifications) { + int notificationId = 1; +// MainActivity→broadcastreseiver(?)に変更 +// Intent intent = new Intent(cosmosBackgroundService, MainActivity.class); +// 以下二行はボタンについてだよ +// PendingIntent pendingIntent = PendingIntent.getActivity(cosmosBackgroundService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); +// android.app.Notification.Action action = new android.app.Notification.Action(R.drawable.notification_icon, "ボタンだよ", pendingIntent); + + android.app.Notification notification = new android.app.Notification.Builder(cosmosBackgroundService) + .setContentTitle("通知タイトル") + .setContentText("通知ないよう") + .setSmallIcon(R.drawable.icon_no) + .setChannelId("cosmos") +// .setGroup("") +// .addAction(action) + .build(); + notificationManager.notify(notificationId, notification); } @Override diff --git a/app/src/main/res/drawable/icon_no.png b/app/src/main/res/drawable/icon_no.png new file mode 100644 index 0000000..807f3e4 --- /dev/null +++ b/app/src/main/res/drawable/icon_no.png Binary files differ