Professional Documents
Culture Documents
Document 55 Broadcast Receiver Notification
Document 55 Broadcast Receiver Notification
Gii thiu v
Broadcast Receiver
trong Android,
Notification
Bi
54
Lp trnh Android
Ni dung bi hc
Lp trnh Android
Lp trnh Android
Lp trnh Android
Lp trnh Android
To Broadcast Receiver:
Lp trnh Android
Bng coding
Bng
Manifest
Lp trnh Android
Hy ng k cho Broadcast
unregisterReceiver(receiver);
Lp trnh Android
Notificat
ion
Dng thng bo trn thanh trng thi ca Android Device (thng
dng ch chy Background)
Biu
tng
Ni dung thng
bo
Tiu thng
bo
Lp trnh Android
Bc 1: To
Builder
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("C thng bo")
.setContentText("Mi bn nhn cp nht version");
Bc 2: To Pending
IntentIntent resultIntent = new Intent(this, XYZActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
Lp trnh Android
Bc 3: Gn cc thnh phn
cho Builder
mBuilder.setContentIntent(resultPendingIntent);
/*Uri uri=
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATIO
N);
mBuilder.setSound(uri);*/
Uri newSound= Uri.parse("android.resource://"
+ getPackageName() + "/" + R.raw.gaugau);
mBuilder.setSound(newSound);
Lp trnh Android
Lp trnh Android
END
Ths. Trn Duy Thanh duythanhcse@gmail.com 0987773061 http://duythanhcse.wordpress.com