xml
<?xml version="1.0" encoding="utf-8"?><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:text="Button" android:id="@+id/button1"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout>


两个Activity
package com.tcl.testnotifycation;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class TestNotificationActivity extends Activity {private NotificationManager mNotificationManager;private PendingIntent mPendingIntent;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);// 点击通知切换到Activity2Intent intent = new Intent(this, Activity2.class);mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);Button button = (Button) findViewById(R.id.button1);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Notification notification = new Notification();notification.icon = R.drawable.icon;// 显示图标notification.tickerText = "test...";// 点击通知用户的内容notification.defaults = Notification.DEFAULT_SOUND;// 默认声音// 通知时震动// notification.defaults = Notification.DEFAULT_VIBRATE;// 通知时屏幕发亮// notification.defaults = Notification.DEFAULT_LIGHTS;notification.setLatestEventInfo(TestNotificationActivity.this,"myNotification", "test test test", mPendingIntent);mNotificationManager.notify(0, notification);}});}}

package com.tcl.testnotifycation;import com.tcl.testnotifycation.R.layout;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.LinearLayout;import android.widget.TextView;public class Activity2 extends Activity{public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        LinearLayout layout = new LinearLayout(this);        TextView textView = new TextView(this);        textView.setText("this is test notifycation");        layout.addView(textView);        setContentView(layout);}}

更多相关文章

  1. Android Wear Preview- 从通知上接收语音输入(Receiving Voice In
  2. Android Wear Preview- 为通知添加多个页面(Adding Pages to a No
  3. Android通知栏消息(基本文字通知)
  4. Android通知Notification学习 及 无法通知解决方案
  5. android 创建快捷方式图标
  6. Android图标靠界面的右边的实现
  7. 修改android桌面图标默认大小
  8. Android 5.1系统禁止通知状态栏下拉
  9. Android 创建悬停通知栏

随机推荐

  1. android 键盘关闭/显示
  2. 检查Android进程当前是否正在后台运行
  3. 2013.12.04 (6)——— android SlidingMenu
  4. android Camera
  5. Android(安卓)GL_OUT_OF_MEMORY
  6. Android(安卓)源码编译
  7. android 加载 网络图片
  8. Android窗口跳转
  9. android 视频流的格式转换(YUV-RGB)
  10. Android中图形参数及图形内存信息获取