notification

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/btn1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="我今天高兴"
android:drawableLeft="@drawable/smile" android:drawablePadding="10dp" />
<Button android:id="@+id/btn4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="使用默认的声音" />
</LinearLayout>
在Main.java关键代码如下:
public class Main extends Activity implements OnClickListener {
private NotificationManager notificationManager;
private void showNotification(String tickerText, String contentTitle,
String contentText, int id, int resId) {

Notification notification = new Notification(resId, tickerText,
java.lang.System.currentTimeMillis());

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
getIntent(), 0);

notification.setLatestEventInfo(this, contentTitle, contentText,
contentIntent);
notificationManager.notify(id, notification);

}
private void setDefaults(String tickerText, String titleText,
String contentText, int id, int resId, int defaults) {
Notification notification = new Notification(resId, tickerText,
java.lang.System.currentTimeMillis());

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, Main.class), 0);

notification.setLatestEventInfo(this, titleText, contentText,
contentIntent);
notification.defaults = defaults;
notificationManager.notify(id, notification);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);

}

}

更多相关文章

  1. 2013.09.02(2)——— android 耳机意外拔出关闭声音
  2. C# 5.0引入了两个关键字 --async和await
  3. 在C/C++中如何使用extern关键字
  4. C语言的关键字有哪些?
  5. c语言中的关键字有哪些类型?
  6. c语言关键字是什么
  7. c语言static关键字的作用是什么
  8. c语言的标识符允许使用关键字吗?
  9. c语言中的关键字有哪些?

随机推荐

  1. [Android] 基于 Linux 命令行构建 Androi
  2. 认识Android中的双向绑定
  3. Android(安卓)NDK学习之 一. Android(安
  4. 浅谈android的selector背景选择器
  5. Android系统框架简单理解
  6. [转载] 解决AndroidStudio连不上Android
  7. 浅谈Android五大布局
  8. apk打包
  9. Android中的Menu功能菜单-OptionsMenu[选
  10. Android(安卓)常用命令