阅读更多
package com.example.notificationtest;import android.os.Bundle;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.view.Menu;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;public class MainActivity extends Activity {NotificationManager notificationManager;Spinner spinner;String[] arr = { "请选择", "face", "folder", "other", "text", "why" };ArrayAdapter adapter;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);spinner = (Spinner) findViewById(R.id.spinner);adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1, arr);adapter.setDropDownViewResource(R.layout.text);spinner.setAdapter(adapter);spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view,int position, long id) {if (position == 1) {setNotifi(R.drawable.face, arr[1]);}if (position == 2) {setNotifi(R.drawable.folder, arr[2]);}if (position == 3) {setNotifi(R.drawable.other, arr[3]);}if (position == 4) {setNotifi(R.drawable.txt, arr[4]);}if (position == 5) {setNotifi(R.drawable.why, arr[5]);}}@Overridepublic void onNothingSelected(AdapterView<?> parent) {// TODO Auto-generated method stub}});}private void setNotifi(int id, String text) {Intent intent = new Intent(this, Test.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);PendingIntent pend = PendingIntent.getActivity(MainActivity.this, 0,intent, 0);Notification notification = new Notification();notification.icon = id;notification.tickerText = text;notification.defaults = Notification.DEFAULT_SOUND;notification.flags = Notification.FLAG_AUTO_CANCEL;notification.setLatestEventInfo(MainActivity.this, "MSN", text, pend);notificationManager.notify(0, notification);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

 

 

更多相关文章

  1. Gradle-Android打包文档
  2. android自定义弹出层
  3. 索尼阅读器 PRS-T1 被黑显露更多 Android(安卓)特性,可跑其它电子
  4. Android(安卓)阅读软件集锦 | 小众软件 > Android
  5. [置顶] 一路16有你,一起17前行。Keep不止,Android不息。
  6. 《Android(安卓)应用之路》 Android(安卓)开发技术选型(博客,新闻,
  7. Android消息机制源码阅读
  8. 阅读郭林《第一行代码》的笔记——第5章 全局大喇叭,详解广播机制
  9. 我的android阅读软件“微读”-做最简单的手机阅读软件

随机推荐

  1. Android获取屏幕宽高的方法
  2. Android获取系统的内存使用率
  3. Android使用binder访问service的方式
  4. Android(安卓)Camera2 Mediacodec编码
  5. android 调节媒体音量
  6. android ScrollView嵌套RecyclerView只显
  7. Android(安卓)平板电脑的判断方法
  8. Android(安卓)手机端与服务端POST数据交
  9. Android(安卓)RectF类的构造函数参数说明
  10. Android(安卓)Drawable绘图