内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Android自定義Notification添加點擊事件-創(chuàng)新互聯(lián)

前言

專業(yè)成都網(wǎng)站建設公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來客戶和效益!成都創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設,五站合一網(wǎng)站設計制作,服務好的網(wǎng)站設計公司,成都網(wǎng)站建設、網(wǎng)站建設負責任的成都網(wǎng)站制作公司!

在上一篇文章中《Notification自定義界面》中我們實現(xiàn)了自定義的界面,那么我們該怎么為自定義的界面添加點擊事件呢?像酷狗在通知欄 有“上一首”,“下一首”等控制按鈕,我們需要對按鈕的點擊事件進行響應,不過方法和之前的點擊設置不一樣,需要另外處理,下面我將進行簡單的說明。

實現(xiàn)

同樣,我們需要一個Service的子類MyService,然后在MyService的onCreate中設置,如下代碼:

public class MyService extends Service {

 public static final String ONCLICK = "com.app.onclick";


 private BroadcastReceiver receiver_onclick = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(ONCLICK)) {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(1000);
   }
  }
 };
 @Override
 public void onCreate() {
  super.onCreate();
  Notification notification = new Notification(R.drawable.ic_launcher,
    "JcMan", System.currentTimeMillis());
  RemoteViews view = new RemoteViews(getPackageName(),R.layout.notification);
  notification.contentView = view;
  IntentFilter filter_click = new IntentFilter();
  filter_click.addAction(ONCLICK);
  //注冊廣播
  registerReceiver(receiver_onclick, filter_click);
  Intent Intent_pre = new Intent(ONCLICK);
  //得到PendingIntent
  PendingIntent pendIntent_click = PendingIntent.getBroadcast(this, 0, Intent_pre, 0);
  //設置監(jiān)聽
  notification.contentView.setOnClickPendingIntent(R.id.btn,pendIntent_click);
  //前臺運行
  startForeground(1, notification);
 }
 @Override
 public IBinder onBind(Intent intent) {
  return null;
 }
}

標題名稱:Android自定義Notification添加點擊事件-創(chuàng)新互聯(lián)
文章路徑:http://www.rwnh.cn/article12/iccgc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、域名注冊、Google用戶體驗、自適應網(wǎng)站建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
西吉县| 紫云| 新巴尔虎右旗| 枞阳县| 汝阳县| 安庆市| 桦甸市| 恩施市| 平乡县| 搜索| 凉山| 鱼台县| 木兰县| 德昌县| 双鸭山市| 昂仁县| 桦甸市| 沿河| 二手房| 银川市| 天气| 徐州市| 通州市| 邵东县| 双辽市| 巴青县| 闸北区| 梅州市| 城步| 兴仁县| 柳江县| 碌曲县| 永德县| 十堰市| 宣化县| 行唐县| 临颍县| 崇左市| 休宁县| 鄂托克前旗| 寻甸|