android Notification 状态栏通知使用示例
2014-04-01 22:09
711 查看
ch7_notification.xml:
ch7_second.xml:
NotificationActivity.java:
SecondActivity.java :
AndroidManifest.xml 中application节点中添加 :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="这是一个Notification使用示例"/> <Button android:id="@+id/bt_sendNotification" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="发送Notification"/> </LinearLayout>
ch7_second.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="这是一个通过Notification启动的Activity"/> </LinearLayout>
NotificationActivity.java:
package com.example.ch7; import com.example.baseexample.R; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.location.GpsStatus.NmeaListener; import android.os.Bundle; import android.view.View; import android.widget.Button; public class NotificationActivity extends Activity { private Button bt_sendNotification = null; private Intent mIntent = null; private PendingIntent mPendingIntent = null; private Notification mNotification = null; private NotificationManager mNotificationManager = null; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.ch7_notification); bt_sendNotification = (Button)findViewById(R.id.bt_sendNotification); bt_sendNotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); mIntent = new Intent(NotificationActivity.this,SecondActivity.class); mPendingIntent = PendingIntent.getActivity(NotificationActivity.this, 0, mIntent, 0); mNotification = new Notification(); mNotification.icon = R.drawable.ic_launcher; mNotification.tickerText="实例"; mNotification.defaults = Notification.DEFAULT_ALL; mNotification.flags = Notification.FLAG_INSISTENT; mNotification.setLatestEventInfo(NotificationActivity.this, "点击查看", "这是一个Notification示例", mPendingIntent); mNotificationManager.notify(1,mNotification); } }); } }
SecondActivity.java :
package com.example.ch7; import com.example.baseexample.R; import android.app.Activity; import android.os.Bundle; public class SecondActivity extends Activity { public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.ch7_second); } }
AndroidManifest.xml 中application节点中添加 :
<activity android:name="com.example.ch7.NotificationActivity" android:label="@string/app_name"></activity> <activity android:name="com.example.ch7.SecondActivity" android:label="@string/app_name"></activity>
相关文章推荐
- android Notification 状态栏通知使用示例
- Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)
- Android状态栏通知Notification使用小结
- Android使用Notification在状态栏上显示通知
- 详解Android中使用Notification实现进度通知栏(示例三)
- Android 状态栏通知Notification的创建与使用
- Android中使用Notification实现宽视图通知栏(Notification示例二)
- Android中使用Notification实现普通通知栏(Notification示例一)
- Android中使用Notification实现状态栏的通知
- 【Android开发】消息提示框与对话框-使用Notification在状态栏上显示通知
- Android中使用Notification实现进度通知栏(Notification示例三)
- Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)
- Android种使用Notification实现通知管理以及自定义通知栏实例(示例四)
- Android中使用Notification实现进度通知栏(Notification示例三)
- Android中使用Notification实现宽视图通知栏(Notification示例二)
- Android中使用Notification实现普通通知栏(Notification示例一)
- Android的通知(Notification)使用详解
- Android 通知使用权(NotificationListenerService)的使用
- [Android]状态栏通知Notification、NotificationManager详解
- Android通知Notification的使用(一)