TestServiceの全体的なリファクタリング #28
| 
						 | 
					@ -72,7 +72,9 @@ public class TestService extends Service {
 | 
				
			||||||
            return flags; // IDが初期化されていない場合は何もしない
 | 
					            return flags; // IDが初期化されていない場合は何もしない
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        createRunningNotificationChannel();
 | 
					        if (!isNotificationChannelCreated(BACKGROUND_CHANNEL_ID)) {
 | 
				
			||||||
 | 
					            createRunningNotificationChannel();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        Intent notificationIntent = new Intent(this, MainActivity.class);
 | 
					        Intent notificationIntent = new Intent(this, MainActivity.class);
 | 
				
			||||||
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
 | 
					        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
 | 
				
			||||||
        Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID)
 | 
					        Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID)
 | 
				
			||||||
| 
						 | 
					@ -94,7 +96,7 @@ public class TestService extends Service {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onCreate() {
 | 
					    public void onCreate() {
 | 
				
			||||||
        super.onCreate();
 | 
					        super.onCreate();
 | 
				
			||||||
        if (!isNotificationChannelCreated()) {
 | 
					        if (!isNotificationChannelCreated(CHANNEL_ID)) {
 | 
				
			||||||
            createAlertNotificationChannel();
 | 
					            createAlertNotificationChannel();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -103,9 +105,9 @@ public class TestService extends Service {
 | 
				
			||||||
     * 通知チャネルが作成されているか確認
 | 
					     * 通知チャネルが作成されているか確認
 | 
				
			||||||
     * @return 通知チャンネルの有無 true: 作成済み false: 未作成
 | 
					     * @return 通知チャンネルの有無 true: 作成済み false: 未作成
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean isNotificationChannelCreated() {
 | 
					    private boolean isNotificationChannelCreated(String channelId) {
 | 
				
			||||||
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
 | 
					        NotificationManager notificationManager = getSystemService(NotificationManager.class);
 | 
				
			||||||
        return notificationManager.getNotificationChannel(CHANNEL_ID) != null;
 | 
					        return notificationManager.getNotificationChannel(channelId) != null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user