사용 NotificationCompat.Builder
하고이를 위해 support-v4-library
프로젝트 로 가져와야 합니다.
int notifyID = 1;
int icon = R.drawable.logo;
int icon_small = R.drawable.logo;
String title = context.getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo);
Intent notificationIntent = new Intent(context, Login.class);
Notification noti = new NotificationCompat.Builder(context)
.setSmallIcon(icon_small)
.setTicker("ticker")
.setLargeIcon(largeIcon)
.setWhen(System.currentTimeMillis())
.setContentTitle(title)
.setContentText("message")
.setContentIntent(contentIntent)
//At most three action buttons can be added
.setAutoCancel(true).build();
자세한 내용은 내 대답 : Android 2.3의 알림 작성기 로 이동하십시오.
-------------------그것이 당신을 위해 일하기를 바랍니다 :)
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(getApplicationContext(), MYDEMOACTIVITY.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MYDEMOACTIVITY.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
프로젝트에 지원 라이브러리 v4를 추가하고
import android.support.v4.app.NotificationCompat;
-------------------유용 할 수 있습니다
NotificationCompat.Builder nBuilder;
nBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Heading")
.setLights(Color.BLUE, 500, 500).setContentText(message)
.setAutoCancel(true).setTicker("Notification")
.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
.setSound(alarmSound);
출처
https://stackoverflow.com/questions/22008833