真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android學(xué)習(xí)之Broadcast的簡(jiǎn)單使用-創(chuàng)新互聯(lián)

本文實(shí)例為大家分享了Android學(xué)習(xí)之Broadcast的使用方法,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、海城網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場(chǎng)景定制成都商城網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為海城等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

實(shí)現(xiàn)開機(jī)啟動(dòng)提示網(wǎng)絡(luò)的廣播

package com.example.luobo.broadcasttest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

 private IntentFilter intentFilter;
 private NetworkChangeReceiver networkChangeReceiver;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  intentFilter = new IntentFilter();//創(chuàng)建一個(gè)過濾器實(shí)例
  intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");//添加接收CONNECTIVITY_CHANGE消息
  networkChangeReceiver = new NetworkChangeReceiver();
  registerReceiver(networkChangeReceiver,intentFilter);
 }

 @Override
 protected void onDestroy() {
  super.onDestroy();
  unregisterReceiver(networkChangeReceiver);
 }

 class NetworkChangeReceiver extends BroadcastReceiver{
  @Override
  public void onReceive(Context context, Intent intent) {
   ConnectivityManager connectivityManager = (ConnectivityManager)
     getSystemService(Context.CONNECTIVITY_SERVICE);//通過此方法獲取ConnectivityManager實(shí)例
   NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();//調(diào)用實(shí)例connectivityManager的getActiveNetworkInfo()方法獲取NetworkInfo實(shí)例
   if (networkInfo != null && networkInfo.isAvailable()){
    Toast.makeText(context,"Network is available",Toast.LENGTH_SHORT).show();
   }else {
    Toast.makeText(context,"Network is unavailable",Toast.LENGTH_SHORT).show();
   }
  }
 }
}


本文名稱:Android學(xué)習(xí)之Broadcast的簡(jiǎn)單使用-創(chuàng)新互聯(lián)
鏈接地址:http://weahome.cn/article/ccdhco.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部