android 入门进修条记 NotificationManager与Notification工具的应用

 

import android.app.Notification; import android.app.NotificationManager;/*声明工具变量*/ private NotificationManager myNotiManager; private Spinner mySpinner; private ArrayAdapter<String> myAdapter; private static final String[] status = { "在线","分开","繁忙中","顿时返来","离线" };



/* 初始化工具 */ myNotiManager= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); mySpinner=(Spinner)findViewById(R.id.mySpinner); myAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,status); /* 应用myspinner_dropdown自界说下拉菜单模式 */ myAdapter.setDropDownViewResource(R.layout.myspinner_dropdown); /* 将ArrayAdapter添加Spinner工具中 */ mySpinner.setAdapter(myAdapter); /* 将mySpinner添加OnItemSelectedListener */ mySpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2,long arg3) { /* 依照选择的item来判定要发哪一个notification */ if(status[arg2].equals("在线")) { setNotiType(R.drawable.msn,"在线"); } else if(status[arg2].equals("分开")) { setNotiType(R.drawable.away,"分开"); } else if(status[arg2].equals("繁忙中")) { setNotiType(R.drawable.busy,"繁忙中"); } else if(status[arg2].equals("顿时返来")) { setNotiType(R.drawable.min,"顿时返来"); } else { setNotiType(R.drawable.offine,"离线"); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); ?>?>

 


 

/* 发出Notification的method */ private void setNotiType(int iconId, String text) { /* 建设新的Intent,作为点击Notification留言条时, * 会运行的Activity */ Intent notifyIntent=new Intent(this,EX05_08_1.class); notifyIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK); /* 建设PendingIntent作为配置递延运行的Activity */ PendingIntent appIntent=PendingIntent.getActivity(EX05_08.this, 0,notifyIntent,0); /* 建设Notication,并配置相关参数 */ Notification myNoti=new Notification(); /* 配置statusbar显示的icon */ myNoti.icon=iconId; /* 配置statusbar显示的文字信息 */ myNoti.tickerText=text; /* 配置notification产生时同时发出默认声音 */ myNoti.defaults=Notification.DEFAULT_SOUND; /* 配置Notification留言条的参数 */ myNoti.setLatestEventInfo(EX05_08.this,"MSN登录状态", text,appIntent); /* 送出Notification */ myNotiManager.notify(0,myNoti); }


 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8495.html