android Notification 状态栏通知使用示例

ch7_notification.xml:

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 <TextView android:layout_width="fill_parent" 7 android:layout_height="wrap_content" 8 android:text="这是一个Notification使用示例"/> 9 <Button android:id="@+id/bt_sendNotification" 10 android:layout_width="fill_parent" 11 android:layout_height="wrap_content" 12 android:text="发送Notification"/> 13 14</LinearLayout>

ch7_second.xml:

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 <TextView android:layout_width="fill_parent" 7 android:layout_height="wrap_content" 8 android:text="这是一个通过Notification启动的Activity"/> 9 10</LinearLayout>

NotificationActivity.java:

1package com.example.ch7; 2 3import com.example.baseexample.R; 4 5import android.app.Activity; 6import android.app.Notification; 7import android.app.NotificationManager; 8import android.app.PendingIntent; 9import android.content.Intent; 10import android.location.GpsStatus.NmeaListener; 11import android.os.Bundle; 12import android.view.View; 13import android.widget.Button; 14 15public class NotificationActivity extends Activity { 16 17 private Button bt_sendNotification = null; 18 private Intent mIntent = null; 19 private PendingIntent mPendingIntent = null; 20 private Notification mNotification = null; 21 private NotificationManager mNotificationManager = null; 22 23 public void onCreate(Bundle savedInstanceState){ 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.ch7_notification); 26 27 bt_sendNotification = (Button)findViewById(R.id.bt_sendNotification); 28 bt_sendNotification.setOnClickListener(new View.OnClickListener() { 29 30 @Override 31 public void onClick(View v) { 32 mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 33 mIntent = new Intent(NotificationActivity.this,SecondActivity.class); 34 mPendingIntent = PendingIntent.getActivity(NotificationActivity.this, 0, mIntent, 0); 35 mNotification = new Notification(); 36 mNotification.icon = R.drawable.ic_launcher; 37 mNotification.tickerText="实例"; 38 mNotification.defaults = Notification.DEFAULT_ALL; 39 mNotification.flags = Notification.FLAG_INSISTENT; 40 mNotification.setLatestEventInfo(NotificationActivity.this, "点击查看", "这是一个Notification示例", mPendingIntent); 41 mNotificationManager.notify(1,mNotification); 42 } 43 }); 44 } 45}

SecondActivity.java :

1package com.example.ch7; 2 3import com.example.baseexample.R; 4 5import android.app.Activity; 6import android.os.Bundle; 7 8public class SecondActivity extends Activity { 9 10 public void onCreate(Bundle savedInstanceState){ 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.ch7_second); 13 } 14}

AndroidManifest.xml 中application节点中添加 :

1 <activity android:name="com.example.ch7.NotificationActivity" android:label="@string/app_name"></activity> 2 <activity android:name="com.example.ch7.SecondActivity" android:label="@string/app_name"></activity>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

android ContextMenu 上下文菜单示例

ch2\_contextmenu.xml:<?xmlversion"1.0"encoding"utf8"?<LinearLayoutxmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_p

android WebView 使用实例

主布局文件:<?xmlversion"1.0"encoding"utf8"?<LinearLayoutxmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"

Android输入法遮挡了输入框,使用android:fitsSystemWindows="true"后界面顶部出现白条

问题1、页面布局文件:<LinearLayoutxmlns:android"http://schemas.android.com/apk/res/android"android:id"@id/layoutorderdetail"android:layoutwidth"matchparent"android:layoutheigh