代码:
package com.my;
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.provider.ContactsContract.CommonDataKinds.Note;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.RemoteViews.RemoteView;
import android.widget.TextView;
public class NotificationActivity extends Activity implements OnClickListener {
private Button btnNotify_all;
private Button btnNotify_lights;
private Button btnNotify_sound;
private Button btnNotify_vibrate;
private Button btnCancelAll;
private Button btnCustomview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.tv);
textView.setText("Buhh");
btnNotify_all = (Button)findViewById(R.id.btnNotify_all);
btnNotify_all.setOnClickListener(this);
btnNotify_lights = (Button)findViewById(R.id.btnNotify_lights);
btnNotify_lights.setOnClickListener(this);
btnNotify_sound = (Button)findViewById(R.id.btnNotify_sound);
btnNotify_sound.setOnClickListener(this);
btnNotify_vibrate = (Button)findViewById(R.id.btnNotify_vibrate);
btnNotify_vibrate.setOnClickListener(this);
btnCancelAll = (Button)findViewById(R.id.btnCancelAll);
btnCancelAll.setOnClickListener(this);
btnCustomview = (Button)findViewById(R.id.btnCustomView);
btnCustomview.setOnClickListener(this);
}
private void showSimple(int id) {
// 第一步
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// 第二步
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
notification.defaults = id;
// 第三步
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// 第四步
notification.setLatestEventInfo(this, "message", "hellow", pendingIntent);
// 第五步
notificationManager.notify(R.layout.main, notification);
}
private void showLedLight() {
// 第一步
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// 第二步
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
// notification.defaults = Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xffffff;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
// 第三步
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// 第四步
notification.setLatestEventInfo(this, "message", "hellow", pendingIntent);
// 第五步
notificationManager.notify(R.layout.main, notification);
}
private void cancelAll() {
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
manager.cancelAll();
}
private void customView() {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.mynotificationview);
contentView.setImageViewResource(R.id.ivShow, R.drawable.icon);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, NotificationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notificationManager.notify(0, notification);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNotify_all:
showSimple(Notification.DEFAULT_ALL);
break;
case R.id.btnNotify_lights:
showLedLight();
break;
case R.id.btnNotify_sound:
showSimple(Notification.DEFAULT_SOUND);
break;
case R.id.btnNotify_vibrate:
showSimple(Notification.DEFAULT_VIBRATE);
break;
case R.id.btnCustomView:
customView();
break;
case R.id.btnCancelAll:
cancelAll();
break;
default:
break;
}
}
}
Views are not attached to the Canvas nor the Surface. The window is tied to a Surface and the ViewRoot asks the Surface for a Canvas that is then used by the Views to draw onto.
00 DCD __intial_sp 01 DCD __iar_program_start 02 DCD NMI_Handler ; NMI Handler 03 DCD HardFault_Handler ; Hard Fault Handler 04 DCD MemManage_Handler ; MPU Fault Handler 05 DCD BusFault_Handler ; Bus Fault Handler 06 DCD UsageFault_Handler ; Usage Fault Handler 07 DCD 0 ; Reserved 08 DCD 0 ; Reserved 09 DCD 0 ; Reserved 10 DCD 0 ; Reserved 11 DCD SVC_Handler ; SVCall Handler 12 DCD DebugMon_Handler ; Debug Monitor Handler 13 DCD 0 ; Reserved 14 DCD PendSV_Handler ; PendSV Handler 15 DCD SysTick_Handler ; SysTick Handler 16 DCD WWDG_IRQHandler ; Window Watchdog 17 DCD PVD_IRQHandler ; PVD through EXTI Line detect 18 DCD TAMPER_IRQHandler ; Tamper 19 DCD RTC_IRQHandler ; RTC 20 DCD FLASH_IRQHandler ; Flash 21 DCD RCC_IRQHandler ; RCC 22 DCD EXTI0_IRQHandler ; EXTI Line 0 23 DCD EXTI1_IRQHandler ; EXTI Line 1 24 DCD EXTI2_IRQHandler ; EXTI Line 2 25 DCD EXTI3_IRQHandler ; EXTI Line 3 26 DCD EXTI4_IRQHandler ; EXTI Line 4 27 DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 28 DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2 29 DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3 30 DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4 31 DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5 32 DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6 33 DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7 34 DCD ADC1_2_IRQHandler ; ADC1 & ADC2 35 DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX 36 DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0 37 DCD CAN1_RX1_IRQHandler ; CAN1 RX1 38 DCD CAN1_SCE_IRQHandler ; CAN1 SCE 39 DCD EXTI9_5_IRQHandler ; EXTI Line 9..5 40 DCD TIM1_BRK_IRQHandler ; TIM1 Break 41 DCD TIM1_UP_IRQHandler ; TIM1 Update 42 DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation 43 DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare 44 DCD TIM2_IRQHandler ; TIM2 45 DCD TIM3_IRQHandler ; TIM3 46 DCD TIM4_IRQHandler ; TIM4 47 DCD I2C1_EV_IRQHandler ; I2C1 Event 48 DCD I2C1_ER_IRQHandler ; I2C1 Error 49 DCD I2C2_EV_IRQHandler ; I2C2 Event 50 DCD I2C2_ER_IRQHandler ; I2C2 Error 51 DCD SPI1_IRQHandler ; SPI1 52 DCD SPI2_IRQHandler ; SPI2 53 DCD USART1_IRQHandler ; USART1 54 DCD USART2_IRQHandler ; USART2 55 DCD USART3_IRQHandler ; USART3 56 DCD EXTI15_10_IRQHandler ; EXTI Line 15..10 57 DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line 58 DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend 59 DCD TIM8_BRK_IRQHandler ; TIM8 Break 60 DCD TIM8_UP_IRQHandler ; TIM8 Update 61 DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation 62 DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare 63 DCD ADC3_IRQHandler ; ADC3 64 DCD FSMC_IRQHandler ; FSMC 65 DCD SDIO_IRQHandler ; SDIO 66 DCD TIM5_IRQHandler ; TIM5 67 DCD SPI3_IRQHandler ; SPI3 68 DCD UART4_IRQHandler ; UART4 69 DCD UART5_IRQHandler ; UART5 70 DCD TIM6_IRQHandler ; TIM6 71 DCD TIM7_IRQHandler ; TIM7 72 DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1 73 DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2 74 DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3 75 DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5