Java tutorial
//package com.java2s; /** * Copyright 2013 ? * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.app.Notification; import android.app.NotificationManager; import android.content.Context; public class Main { public static NotificationManager showNotification(Context context, String title, String message, String alertmessage, int icon, Class<?> forwordActivity) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // The PendingIntent to launch our activity if the user selects this // notification // PendingIntent contentIntent = PendingIntent.getActivity(context, 0, // new Intent(context, forwordActivity), 0); // construct the Notification object. Notification noti = new Notification(); noti.icon = icon; noti.tickerText = alertmessage; noti.when = System.currentTimeMillis(); // Set the info for the views that show in the notification panel. // noti.setLatestEventInfo(context, title, message, contentIntent); // after a 100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms. noti.vibrate = new long[] { 100, 250, 100, 500 }; // Note that we use R.layout.incoming_message_panel as the ID for // the notification. It could be any integer you want, but we use // the convention of using a resource id for a string related to // the notification. It will always be a unique number within your // application. nm.notify(1, noti); return nm; } }