<시간/> 이 예제는 Android에서 알림 수로 작업 표시줄에 아이콘을 만드는 방법을 보여줍니다. 1단계 − Android Studio에서 새 프로젝트를 생성하고 파일 ⇒ 새 프로젝트로 이동하여 필요한 모든 세부 정보를 입력하여 새 프로젝트를 생성합니다. 2단계 − res/layout/activity_main.xml에 다음 코드를 추가합니다. <전> <버튼 안드로이드 :layout_width ="match_parent" android :layout_height ="wrap_content" android :layout_centerInParent ="true" android :layout_margin ="16dp" android :onClick ="createNotification" android :text ="알림 생성" /> 3단계 − src/MainActivity에 다음 코드를 추가합니다. 패키지 app.tutorialspoint.com.notifyme;import android.app.NotificationChannel;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android. support.v4.app.NotificationCompat;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.TextView;public class MainActivity extends AppCompatActivity { public static final String NOTIFICATION_CHANNEL_ID ="10001"; 개인 최종 정적 문자열 default_notification_channel_id ="기본"; 정적 int 알림 수 =0; TextView tvBadgeNumber; @Override 보호된 무효 onCreate(SavedInstanceState 번들) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvBadgeNumber =findViewById(R.id. tvBadgeNumber ); } 공개 무효 createNotification(보기 보기) { 의도 알림 인텐트 =new Intent(getApplicationContext() , MainActivity.class ); notificationIntent.putExtra( "fromNotification" , true ); notificationIntent.setFlags(의도.FLAG_ACTIVITY_CLEAR_TOP | 의도.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent PendingIntent =PendingIntent. getActivity( this, 0, notificationIntent, 0); 알림 관리자 mNotificationManager =(알림 관리자) getSystemService( NOTIFICATION_SERVICE ); NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(MainActivity. this, default_notification_channel_id ); mBuilder.setContentTitle( "내 알림" ); mBuilder.setContentIntent(pendingIntent); mBuilder.setContentText( "알림 리스너 서비스 예제" ); mBuilder.setTicker( "알림 리스너 서비스 예제" ); mBuilder.setSmallIcon(R.drawable.ic_launcher_foreground); mBuilder.setAutoCancel( true ); if (android.os.Build.VERSION. SDK_INT>=android.os.Build.VERSION_CODES. O ) { int 중요도 =NotificationManager. IMPORTANCE_HIGH; NotificationChannel notificationChannel =new NotificationChannel( NOTIFICATION_CHANNEL_ID , "NOTIFICATION_CHANNEL_NAME" , 중요도); mBuilder.setChannelId( NOTIFICATION_CHANNEL_ID ); 어설션 mNotificationManager !=null; mNotificationManager.createNotificationChannel(notificationChannel); } 어설션 mNotificationManager !=null; mNotificationManager.notify(( int ) 시스템.currentTimeMillis() , mBuilder.build()); 알림 수 ++; tvBadgeNumber .setText(String.valueOf(notificationCount)); }} 4단계 − res/drawable/item_count.xml에 다음 코드 추가 <전> <코너 안드로이드:반경 ="8dp" /> <솔리드 안드로이드 :color ="#2196F3" /> <스트로크 안드로이드 :width ="1dip" 안드로이드 :color ="#FFF" /> <패딩 안드로이드:bottom ="2dp" 안드로이드 :left ="2dp" android :right ="2dp" android :top ="2dp" /> 5단계 − AndroidManifest.xml에 다음 코드 추가 <전>