最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法實(shí)例分析

 更新時間:2019年03月16日 09:38:43   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法,結(jié)合實(shí)例形式分析了Android Notification手機(jī)狀態(tài)欄通知的常見函數(shù)、功能及使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法。分享給大家供大家參考,具體如下:

簡介:

通知是顯示在手機(jī)狀態(tài)欄的通知(PS:就是手機(jī)上方,顯示時間啥的那一欄)

用法:

Notification添加了Builder()類,其包含如下方法:

1. setDefaults()         通知led燈、音樂、震動等

2. setAutoChange()  設(shè)置點(diǎn)擊通知后,通知自動從狀態(tài)欄刪除

3. setContentTitle()   通知標(biāo)題

4. setContentText()  通知內(nèi)容

5. setSmallcon()      為通知設(shè)置圖標(biāo)

6. setLargelcon()       為通知設(shè)置大圖標(biāo)

7. setTick()               設(shè)置通知狀態(tài)欄的提示文本

8. setContentIntent()點(diǎn)擊通知后要啟動的相應(yīng)組件

運(yùn)行效果:

實(shí)現(xiàn)方法:

1.首先建立一個活動用來執(zhí)行:

public class MainActivity extends Activity {
  static final int NOTIFICATION_ID = 0x123;
  NotificationManager notificationManager;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //獲取系統(tǒng)的Notification對象
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
   }
  //為發(fā)送通知的按鈕點(diǎn)擊事件定義事件處理方法
  @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
  public void send(View source){
    //創(chuàng)建一個其他Activity的Intent
    Intent intent = new Intent(MainActivity.this,TextActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0);
    Notification notification = new Notification.Builder(this)
        //設(shè)置打開通知 通知自動消失
        .setAutoCancel(true)
        //設(shè)置顯示狀態(tài)欄的通知提示信息
        .setTicker("注目提醒!")
        //設(shè)置通知圖標(biāo)
        .setSmallIcon(R.drawable.seek02)
        //設(shè)置通知內(nèi)容標(biāo)題
        .setContentTitle("該應(yīng)用發(fā)生 爆炸大 大 大 新聞??!")
        //設(shè)置通知內(nèi)容
        .setContentText("冒險沒有 你手機(jī)自嗨罷了~")
        //設(shè)置使用默認(rèn)的聲音 LED燈
        .setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS)
        //設(shè)置通知自定義聲音
//        .setSound()
        .setWhen(System.currentTimeMillis())
        //設(shè)置他只要啟動的程序Intent
        .setContentIntent(pendingIntent)
        .build();
    notificationManager.notify(NOTIFICATION_ID,notification);
  }
  public void del(View view){
    //取消通知
    notificationManager.cancel(NOTIFICATION_ID);
  }
}

2.然后建立一個要打開的活動(隨意建就行)(布局文件任意我這里就不寫了)

public class TextActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_t_exta_ctivity);
  }
}

最后記得添加權(quán)限(mainfest)

<!--消息通知使用到閃光燈和聲音權(quán)限-->
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.VIBRATE"/>

PS:關(guān)于Android權(quán)限控制可參考~
Android Manifest功能與權(quán)限描述大全: http://tools.jb51.net/table/AndroidManifest

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論

济源市| 陈巴尔虎旗| 得荣县| 松原市| 都昌县| 临泽县| 龙游县| 白城市| 清苑县| 陕西省| 华坪县| 兴业县| 凤阳县| 舞阳县| 长沙市| 防城港市| 年辖:市辖区| 泾川县| 浦县| 礼泉县| 新竹市| 汝州市| 英超| 双鸭山市| 和田市| 阳春市| 万荣县| 山丹县| 兴国县| 稻城县| 抚顺市| 新化县| 华阴市| 扎鲁特旗| 常德市| 宣城市| 简阳市| 萝北县| 黔西| 渝中区| 平罗县|