TestServiceの全体的なリファクタリング #28
| @ -145,9 +145,16 @@ public class TestService extends Service { | ||||
|         return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); | ||||
|     } | ||||
| 
 | ||||
|     private void vibrateDevice() { | ||||
|         Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); | ||||
|         if (vibrator.hasVibrator()) { | ||||
|             vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void Notification(Context context) {//実際に通知を行うメソッド | ||||
| 
 | ||||
|         ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション | ||||
|         vibrateDevice(); | ||||
| 
 | ||||
|         @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) | ||||
|                 .setSmallIcon(android.R.drawable.ic_menu_info_details) | ||||
| @ -172,11 +179,7 @@ public class TestService extends Service { | ||||
|         if (ActivityCompat.checkSelfPermission(this, | ||||
|                 android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; | ||||
| 
 | ||||
| 
 | ||||
|         Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); | ||||
|         if (vibrator.hasVibrator()) { | ||||
|             vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); | ||||
|         } | ||||
|         vibrateDevice(); | ||||
| 
 | ||||
|         NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) | ||||
|                 .setSmallIcon(android.R.drawable.ic_menu_info_details) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user