package com.test.hellonotification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class MainNotification extends ActionBarActivity {
private NotificationManager notificationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取系统通知管理器
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Spinner s = (Spinner) findViewById(R.id.spinner01);
//创建下拉列表数组适配器
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.logStatus,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
//下拉列表选择事件
AdapterView.OnItemSelectedListener oisl = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
case 0:
showNotification("登录状态","MSN登录状态","在线",R.drawable.msn,R.drawable.msn);
break;
case 1:
showNotification("登录状态","MSN登录状态","离线",R.drawable.msn,R.drawable.offine);
break;
case 2:
showNotification("登录状态","MSN登录状态","隐身",R.drawable.msn,R.drawable.away);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
s.setOnItemSelectedListener(oisl);
}
//显示系统通知
private void showNotification(String tickerText,String contentTitle,String contentText,int id,int resId){
Notification notification = new Notification(resId,tickerText,System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this,0,getIntent(),0);
notification.setLatestEventInfo(this,contentTitle,contentText,contentIntent);
notificationManager.notify(id,notification);
}
}
Android系统通知Notification
最新推荐文章于 2023-12-26 11:53:38 发布