日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Notification的功能和用法 加薪通知

發布時間:2023/12/18 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Notification的功能和用法 加薪通知 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實現通知欄消息的生成和消除

  • MainActivity.java??
  • public?class?MainActivity?extends?Activity??
  • {??
  • ????static?final?int?NOTIFICATION_ID?=?0x123;??
  • ????NotificationManager?nm;??
  • ????@Override??
  • ????public?void?onCreate(Bundle?savedInstanceState)??
  • ????{??
  • ????????super.onCreate(savedInstanceState);??
  • ????????setContentView(R.layout.main);??
  • ????????//?獲取系統的NotificationManager服務??
  • ????????nm?=?(NotificationManager)??
  • ????????????????getSystemService(NOTIFICATION_SERVICE);??
  • ????}??
  • ????//?為發送通知的按鈕的點擊事件定義事件處理方法??
  • ????public?void?send(View?source)??
  • ????{??
  • ????????//?創建一個啟動其他ActivityIntent??
  • ????????Intent?intent?=?new?Intent(MainActivity.this??
  • ????????????????,?OtherActivity.class);??
  • ????????PendingIntent?pi?=?PendingIntent.getActivity(??
  • ????????????????MainActivity.this,?0,?intent,?0);??
  • ????????Notification?notify?=?new?Notification.Builder(this)??
  • ????????????????//?設置打開該通知,該通知自動消失??
  • ????????????????.setAutoCancel(true)??
  • ????????????????//?設置顯示在狀態欄的通知提示信息??
  • ????????????????.setTicker("有新消息")??
  • ????????????????//?設置通知的圖標??
  • ????????????????.setSmallIcon(R.drawable.notify)??
  • ????????????????//?設置通知內容的標題??
  • ????????????????.setContentTitle("一條新通知")??
  • ????????????????//?設置通知內容??
  • ????????????????.setContentText("恭喜你,您加薪了,工資增加20%!")??
  • ????????????????//?設置使用系統默認的聲音、默認LED??
  • ????????????????//?.setDefaults(Notification.DEFAULT_SOUND??
  • ????????????????//?|Notification.DEFAULT_LIGHTS)??
  • ????????????????//?設置通知的自定義聲音??
  • ????????????????.setSound(Uri.parse("android.resource://org.crazyit.ui/"??
  • ????????????????????????+?R.raw.msg))??
  • ????????????????.setWhen(System.currentTimeMillis())??
  • ????????????????//?設改通知將要啟動程序的Intent??
  • ????????????????.setContentIntent(pi)??//?①??
  • ????????????????.build();??
  • ????????//?發送通知??
  • ????????nm.notify(NOTIFICATION_ID,?notify);??
  • ????}??
  • ????//?為刪除通知的按鈕的點擊事件定義事件處理方法??
  • ????public?void?del(View?v)??
  • ????{??
  • ????????//?取消通知??
  • ????????nm.cancel(NOTIFICATION_ID);??
  • ????}??
  • }??
  • OtherActivity??
  • public?class?OtherActivity?extends?Activity??
  • {??
  • ???@Override??
  • ???public?void?onCreate(Bundle?savedInstanceState)??
  • ???{??
  • ??????super.onCreate(savedInstanceState);??
  • ??????//設置該Activity顯示的頁面??
  • ??????setContentView(R.layout.other);??
  • ???}??
  • }??
  • XML文件??
  • <?xml?version="1.0"?encoding="utf-8"?>??
  • <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"??
  • ???android:orientation="horizontal"??
  • ???android:layout_width="match_parent"??
  • ???android:layout_height="match_parent"??
  • ???android:gravity="center_horizontal">??
  • <Button??
  • ???android:layout_width="wrap_content"???
  • ???android:layout_height="wrap_content"???
  • ???android:text="發送Notification"??
  • ???android:onClick="send"??
  • ???/>??
  • <Button??
  • ???android:layout_width="wrap_content"???
  • ???android:layout_height="wrap_content"???
  • ???android:text="刪除Notification"??
  • ???android:onClick="del"??
  • ???/>???
  • </LinearLayout>??
  • other.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="wrap_content"??
  • ???android:gravity="center_horizontal"??
  • ???android:orientation="vertical">??
  • <!--?定義一個ImageView?-->??
  • <ImageView??
  • ???android:layout_width="match_parent"??
  • ???android:layout_height="wrap_content"??
  • ???android:src="@drawable/swift"??
  • ???android:layout_gravity="center_horizontal"??
  • ???/>??
  • </LinearLayout>??
  • Menu.xml??
  • <menu?xmlns:android="http://schemas.android.com/apk/res/android"??
  • ?????xmlns:tools="http://schemas.android.com/tools"??
  • ?????tools:context=".MainActivity">??
  • ???<item?android:id="@+id/action_settings"??
  • ????????android:title="@string/app_name"??
  • ????????android:orderInCategory="100"??
  • ????????android:showAsAction="never"/>??
  • </menu>??
  • ?

    效果

    ?

    轉載于:https://www.cnblogs.com/wwjldm/p/6930567.html

    總結

    以上是生活随笔為你收集整理的Notification的功能和用法 加薪通知的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。