statusbar—NOTIFICATION
来源:互联网 发布:模拟退火算法模型 编辑:程序博客网 时间:2024/04/20 18:59
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_1_4789227" name="code" class="html">最近开始关注通知流程,写个小例子:<pre code_snippet_id="216524" snippet_file_name="blog_20140304_1_4789227" name="code" class="html">public class MainActivity extends Activity {public Button mButtonSend;
public Button mButtonCancel;
public Button mButtonOther;
public TextView mTextSend;
public TextView mTextCancel;
public TextView mTextOther;
public NotificationManager mNotiManager;
public Notification mNoti;
private PendingIntent mPDIntent;
public static final int NOTIFICATIO_TEST_ID = 1;
public static final int NOTIFICATIO_TEST_ID_OTHER = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_18_8119151" name="code" class="html">private void init() {
mButtonSend = (Button) findViewById(R.id.button1);
mButtonCancel = (Button) findViewById(R.id.button2);
mButtonOther = (Button) findViewById(R.id.button3);
mTextSend = (TextView) findViewById(R.id.textView1);
mTextCancel = (TextView) findViewById(R.id.textView2);
mTextOther = (TextView) findViewById(R.id.textView3);
mButtonSend.setOnClickListener(buttonListener);
mButtonCancel .setOnClickListener(buttonListener);
mButtonOther .setOnClickListener(buttonListener);
mNotiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent mIntent = new Intent(this, pd_intent.class);
mPDIntent = PendingIntent.getActivity(MainActivity.this, 0, mIntent, 0);
}
private OnClickListener buttonListener =new View.OnClickListener(){
public void onClick(View v){
switch (v.getId()) {
case R.id.button1:
sendNotification();
break;
case R.id.button2:
cancelNotification();
break;
case R.id.button3:
sendNotificationOther();
break;
default:
break;
}
}
private void sendNotificationOther() {
mNoti = new Notification();
mNoti.icon = R.drawable.ic_launcher;
mNoti.tickerText = "haha ?";
mNoti.when = System.currentTimeMillis();
//<span style="font-family: Arial, Helvetica, sans-serif;">mNoti.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知界面跳转后自动清除通知,不跳转不取消</span>
<span style="font-family: Arial, Helvetica, sans-serif;">mNoti.setLatestEventInfo(MainActivity.this, "title", "点击跳转,通知不能自动清除", mPDIntent);</span>
mNotiManager.notify(NOTIFICATIO_TEST_ID_OTHER, mNoti);
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_58_7090701" name="code" class="html">取消通知:
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_59_7407129" name="code" class="html">private void cancelNotification() {
mNotiManager.cancelAll();//取消该NotificationManager管理的所有通知
//mNotiManager.cancel(NOTIFICATIO_TEST_ID);//取消该NotificationManager管理的NOTIFICATIO_TEST_ID通知
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_64_4529164" name="code" class="html">发送通知:
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_65_6274050" name="code" class="html">private void sendNotification() {
mNoti = new Notification();
mNoti.icon = R.drawable.ic_launcher;
mNoti.tickerText = "This is test for notification,are you right?";
mNoti.when = System.currentTimeMillis();
mNoti.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知界面跳转后自动清除通知
mNoti.setLatestEventInfo(MainActivity.this,"TITLE", "点击跳转,通知自动清除", mPDIntent);
mNotiManager.notify(NOTIFICATIO_TEST_ID, mNoti);
}
};
public class MainActivity extends Activity {public Button mButtonSend;
public Button mButtonCancel;
public Button mButtonOther;
public TextView mTextSend;
public TextView mTextCancel;
public TextView mTextOther;
public NotificationManager mNotiManager;
public Notification mNoti;
private PendingIntent mPDIntent;
public static final int NOTIFICATIO_TEST_ID = 1;
public static final int NOTIFICATIO_TEST_ID_OTHER = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_93_4447096" name="code" class="html">private void init() {
mButtonSend = (Button) findViewById(R.id.button1);
mButtonCancel = (Button) findViewById(R.id.button2);
mButtonOther = (Button) findViewById(R.id.button3);
mTextSend = (TextView) findViewById(R.id.textView1);
mTextCancel = (TextView) findViewById(R.id.textView2);
mTextOther = (TextView) findViewById(R.id.textView3);
mButtonSend.setOnClickListener(buttonListener);
mButtonCancel .setOnClickListener(buttonListener);
mButtonOther .setOnClickListener(buttonListener);
mNotiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent mIntent = new Intent(this, pd_intent.class);
mPDIntent = PendingIntent.getActivity(MainActivity.this, 0, mIntent, 0);
}
private OnClickListener buttonListener =new View.OnClickListener(){
public void onClick(View v){
switch (v.getId()) {
case R.id.button1:
sendNotification();
break;
case R.id.button2:
cancelNotification();
break;
case R.id.button3:
sendNotificationOther();
break;
default:
break;
}
}
private void sendNotificationOther() {
mNoti = new Notification();
mNoti.icon = R.drawable.ic_launcher;
mNoti.tickerText = "haha ?";
mNoti.when = System.currentTimeMillis();
//<span style="font-family: Arial, Helvetica, sans-serif;">mNoti.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知界面跳转后自动清除通知,不跳转不取消</span>
<span style="font-family: Arial, Helvetica, sans-serif;">mNoti.setLatestEventInfo(MainActivity.this, "title", "点击跳转,通知不能自动清除", mPDIntent);</span>
mNotiManager.notify(NOTIFICATIO_TEST_ID_OTHER, mNoti);
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_133_9973083" name="code" class="html">private void cancelNotification() {
mNotiManager.cancelAll();//取消该NotificationManager管理的所有通知
//mNotiManager.cancel(NOTIFICATIO_TEST_ID);//取消该NotificationManager管理的NOTIFICATIO_TEST_ID通知
}
</pre><pre code_snippet_id="216524" snippet_file_name="blog_20140304_138_2078608" name="code" class="html">private void sendNotification() {
mNoti = new Notification();
mNoti.icon = R.drawable.ic_launcher;
mNoti.tickerText = "This is test for notification,are you right?";
mNoti.when = System.currentTimeMillis();
mNoti.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知界面跳转后自动清除通知
mNoti.setLatestEventInfo(MainActivity.this,"TITLE", "点击跳转,通知自动清除", mPDIntent);
mNotiManager.notify(NOTIFICATIO_TEST_ID, mNoti);
}
};
附:
<p>下拉每条通知布局:notification_template_base.xml</p><p>xml<span style="font-family:宋体;">路径:</span><span style="font-family:Calibri;">framework/base/core/res/res/layout/</span></p>
0 0
- statusbar—NOTIFICATION
- Android-StatusBar+Notification
- statusbar-notification小例子
- Android 4.0 ICS SystemUI浅析——StatusBar加载流程之Notification
- Android 4.0 ICS SystemUI浅析——StatusBar加载流程之Notification
- StatusBar下拉Notification宽度满屏解决方法
- StatusBar下拉Notification宽度满屏解决方法
- 魅族MX2 --点击notification收起 StatusBar
- Android7.0 SystemUI StatusBar和Notification代码浅析
- statusbar—状态栏对外
- statusbar—SIM broadcast
- StatusBar
- statusbar
- StatusBar
- statusBar
- StatusBar
- Android FrameWork——StatusBar
- Android FrameWork——StatusBar
- Modelsim仿真学习指南
- AMD x2 ubuntu12.04 64bit基于emulator调试Android4.0.3源代码( system_process进程)
- ModelSim仿真流程
- request.setAttribute()、session.setAttribute()和request.getParameter()的联系与区别
- PAT 1047. Student List for Course
- statusbar—NOTIFICATION
- Linux 基本命令
- oracle的多表联接查询用法
- EBS 库存(Inventory)模块中组织复制功能(Organization Copy)介绍
- Java中字符串的“引用”传递
- 两个特殊的流对象(System.in和System.out)及打印流
- ORACLE LOB大对象处理
- ext 如何添加tabpanel
- maven 执行命令mvn help:system命令时报build failure错误的解决办法。