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

Android實(shí)現(xiàn)為Notification加上一個進(jìn)度條的方法

 更新時間:2016年10月24日 15:15:00   作者:老碼農(nóng)豆豆  
這篇文章主要介紹了Android實(shí)現(xiàn)為Notification加上一個進(jìn)度條的方法,結(jié)合實(shí)例形式分析了Android針對Notification組件的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android實(shí)現(xiàn)為Notification加上一個進(jìn)度條的方法。分享給大家供大家參考,具體如下:

package com.notification;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.Toast;
public class nofificationActivity extends Activity implements OnClickListener {
  private static final int NOTIFICATION_ID = 0x12;
  private Notification notification = null;
  private NotificationManager manager = null;
  public Handler handler;
  private int _progress = 0;
  private Thread thread = null;
  private boolean isStop = false;
  // 當(dāng)界面處理停止的狀態(tài) 時,設(shè)置讓進(jìn)度條取消
  @Override
  protected void onPause() {
    // TODO Auto-generated method stub
    isStop = false;
    manager.cancel(NOTIFICATION_ID);
    super.onPause();
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button btn = (Button) findViewById(R.id.Button01);
    btn.setOnClickListener(this);
    notification = new Notification(R.drawable.icon, "帶進(jìn)條的提醒", System
        .currentTimeMillis());
    notification.icon = R.drawable.icon;
    // 通過RemoteViews 設(shè)置notification中View 的屬性
    notification.contentView = new RemoteViews(getApplication()
        .getPackageName(), R.layout.custom_dialog);
    notification.contentView.setProgressBar(R.id.pb, 100, 0, false);
    notification.contentView.setTextViewText(R.id.tv, "進(jìn)度" + _progress
        + "%");
    // 通過PendingIntetn
    // 設(shè)置要跳往的Activity,這里也可以設(shè)置發(fā)送一個服務(wù)或者廣播,
    // 不過在這里的操作都必須是用戶點(diǎn)擊notification之后才觸發(fā)的
    notification.contentIntent = PendingIntent.getActivity(this, 0,
        new Intent(this, remoteView.class), 0);
    // 獲得一個NotificationManger 對象,此對象可以對notification做統(tǒng)一管理,只需要知道ID
    manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  }
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    isStop = true;
    manager.notify(NOTIFICATION_ID, notification);
    thread = new Thread(new Runnable() {
      @Override
      public void run() {
        Thread.currentThread();
        // TODO Auto-generated method stub
        while (isStop) {
          _progress += 10;
          Message msg = handler.obtainMessage();
          msg.arg1 = _progress;
          msg.sendToTarget();
          try {
            Thread.sleep(500);
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    });
    thread.start();
    handler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        notification.contentView.setProgressBar(R.id.pb, 100, msg.arg1,
            false);
        notification.contentView.setTextViewText(R.id.tv, "進(jìn)度"
            + msg.arg1 + "%");
        manager.notify(NOTIFICATION_ID, notification);
        if (msg.arg1 == 100) {
          _progress = 0;
          manager.cancel(NOTIFICATION_ID);
          isStop = false;
          Toast.makeText(nofificationActivity.this, "下載完畢", 1000)
              .show();
        }
        super.handleMessage(msg);
      }
    };
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

  • Android Application的使用全面解析

    Android Application的使用全面解析

    這篇文章主要為大家介紹了Android Application的使用全面解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android實(shí)現(xiàn)登陸界面的記住密碼功能

    Android實(shí)現(xiàn)登陸界面的記住密碼功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)登陸界面的記住密碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 自定義Android六邊形進(jìn)度條(附源碼)

    自定義Android六邊形進(jìn)度條(附源碼)

    這篇文章主要介紹了自定義Android六邊形進(jìn)度條,本文設(shè)計(jì)的進(jìn)度條是六邊形的,對進(jìn)度條感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android Map新用法:MapFragment應(yīng)用介紹

    Android Map新用法:MapFragment應(yīng)用介紹

    MapView ,MapActivity 這種的局限在于,必須要繼承MapActivity,否則無法使用MapView,但是,MapFragment 這種的局限在于,必須要安裝Google Play Service ,也就是說必須是原生rom。而且sdk要在12以上
    2013-01-01
  • android文件管理器用法詳解

    android文件管理器用法詳解

    這篇文章主要為大家詳細(xì)介紹了android文件管理器的用法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android開發(fā)vsts?agent支持自定義task過程詳解

    Android開發(fā)vsts?agent支持自定義task過程詳解

    這篇文章主要介紹了Android開發(fā)vsts?agent支持自定義task過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-04-04
  • 如何設(shè)置Android studio 3.0顯示光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo)

    如何設(shè)置Android studio 3.0顯示光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo)

    這篇文章主要介紹了如何設(shè)置Android studio 3.0顯示光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo) 很多朋友反映剛升級了Android studio 3.0,發(fā)現(xiàn)光標(biāo)返回上一次瀏覽位置的箭頭圖標(biāo)沒有了,下文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2017-11-11
  • Android富文本實(shí)現(xiàn)的幾種方式匯總

    Android富文本實(shí)現(xiàn)的幾種方式匯總

    由于項(xiàng)目中需要使用到富文本顯示和編輯,索性整理下,這篇文章主要給大家介紹了關(guān)于Android富文本實(shí)現(xiàn)的幾種方式,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-05-05
  • Recycleview實(shí)現(xiàn)無限自動輪播

    Recycleview實(shí)現(xiàn)無限自動輪播

    這篇文章主要為大家詳細(xì)介紹了Recycleview實(shí)現(xiàn)無限自動輪播,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android Studio做超好玩的拼圖游戲 附送詳細(xì)注釋源碼

    Android Studio做超好玩的拼圖游戲 附送詳細(xì)注釋源碼

    這篇文章主要介紹了用Android Studio做的一個超好玩的拼圖游戲,你是0基礎(chǔ)Android小白也能包你學(xué)會,另外附送超詳細(xì)注釋的源碼,建議收藏!
    2021-08-08

最新評論

淮北市| 乌拉特后旗| 慈溪市| 商南县| 榆林市| 仲巴县| 福州市| 象山县| 军事| 松滋市| 永修县| 郸城县| 吉木乃县| 灵宝市| 揭西县| 宜城市| 揭阳市| 寿阳县| 东山县| 福鼎市| 咸宁市| 富源县| 钟山县| 连云港市| 甘孜| 曲麻莱县| 来凤县| 瓦房店市| 高雄市| 恩平市| 溆浦县| 高清| 华宁县| 乌海市| 屏边| 永丰县| 汉川市| 开远市| 上饶市| 江油市| 本溪市|