में यह कोड जोड़ें अधिक जानकारी के लिए इस Link देखें। अपने मैनिफ़ेस्ट फ़ाइल को
जोड़ें अनुमति
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
संपादित // 1. अधिसूचना NotificationManager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
// 2. का दृष्टांत के लिए एक संदर्भ जाओ
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// 3. परिभाषित करें ई अधिसूचना के विस्तार संदेश और आशय
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);
// 4. पास अधिसूचना NotificationManager
private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
// करने के लिए ----------------- ----- // ध्वनि जोड़ें // ---------------------- // ए। डिफ़ॉल्ट ध्वनि
notification.defaults |= Notification.DEFAULT_SOUND;
// बी। एसडी कार्ड से कस्टम ध्वनि
notification.sound = Uri.parse("file:///sdcard/notification/SOUND.mp3");
// ---------------------- // कंपन जोड़े // ------ ---------------- // ए। डिफ़ॉल्ट कंपन
notification.defaults |= Notification.DEFAULT_VIBRATE;
// बी। कस्टम कंपन
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
// ------------------------ // चमक रोशनी // जोड़े ------ ------------------ // ए। डिफ़ॉल्ट रोशनी
notification.defaults |= Notification.DEFAULT_LIGHTS;
// बी। कस्टम रोशनी
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;