CosmosBackgroundServiceの開始をCosmosで制御するようにした変更の再修正
commit 0cf2d6b646f643d8ba1e655cb91e61a28fbcdfe2
2 parents 55d92c9 + ba03ddd
a-hongo authored on 14 Nov 2019
Showing 3 changed files
View
2
■■■
app/build.gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.cosmosclient"
minSdkVersion 15
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
View
27
app/src/main/java/com/example/cosmosclient/services/CosmosBackgroundService.java
private List<Notification> notifications =null;
private CosmosLocation LOC = new CosmosLocation();
private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定
private int count = 0;
private NotificationManager notificationManager;
 
public CosmosBackgroundService() {
super("CosmosBackgroundService");
Log.d(TAG, "Constructor");
super.onCreate();
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
public void onStart(@Nullable Intent intent, int startId) {
Log.d(TAG, "lon:" + location.getLongitude());
 
updateAreaInformation(location);
this.notifications=searchNotifications(cosmos,location);
sendNotifications(this, notifications);
 
 
}
 
private void sendNotifications(CosmosBackgroundService cosmosBackgroundService, List<Notification> 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
public void onStatusChanged(String provider, int status, Bundle extras) {
View
app/src/main/res/drawable/icon_no.png 0 → 100644