Friday, November 12, 2010

Notification In Android App (二)

原來google api 好多寶, 但佢個結構設計太差了

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
 
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
 
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
 
private static final int HELLO_ID = 1;

mNotificationManager.notify(HELLO_ID, notification);
 
 
更多資料就繼續看吧 
 
加聲:
notification.defaults |= Notification.DEFAULT_SOUND;
或者
notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
又或者
notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
 
加震:
notification.defaults |= Notification.DEFAULT_VIBRATE;
想震得特色d 
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
單數(第一個item 係 1) 位的是off, 雙數位的是 on
 
想閃:
notification.defaults |= Notification.DEFAULT_LIGHTS;
變色:
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
 
 
重有多d 
 

More features

You can add several more features to your notifications using Notification fields and flags. Some useful features include the following:
"FLAG_AUTO_CANCEL" flag
Add this to the flags field to automatically cancel the notification after it is selected from the Notifications window.
"FLAG_INSISTENT" flag
Add this to the flags field to repeat the audio until the user responds.
"FLAG_ONGOING_EVENT" flag
Add this to the flags field to group the notification under the "Ongoing" title in the Notifications window. This indicates that the application is on-going — its processes is still running in the background, even when the application is not visible (such as with music or a phone call).
"FLAG_NO_CLEAR" flag
Add this to the flags field to indicate that the notification should not be cleared by the "Clear notifications" button. This is particularly useful if your notification is on-going.
number field
This value indicates the current number of events represented by the notification. The appropriate number is overlaid on top of the status bar icon. If you intend to use this field, then you must start with "1" when the Notification is first created. (If you change the value from zero to anything greater during an update, the number is not shown.)
iconLevel field
This value indicates the current level of a LevelListDrawable that is used for the notification icon. You can animate the icon in the status bar by changing this value to correlate with the drawable's defined in a LevelListDrawable. See the LevelListDrawable reference for more information.
See the Notification class reference for more information about additional features that you can customize for your application.
   

     

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home