Example usage for android.net ConnectivityManager TYPE_MOBILE

List of usage examples for android.net ConnectivityManager TYPE_MOBILE

Introduction

In this page you can find the example usage for android.net ConnectivityManager TYPE_MOBILE.

Prototype

int TYPE_MOBILE

To view the source code for android.net ConnectivityManager TYPE_MOBILE.

Click Source Link

Document

A Mobile data connection.

Usage

From source file:org.basdroid.common.NetworkUtils.java

public static boolean isLTE(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        return false;
    }/*from w  w  w  . jav a2s.c  o m*/

    int type = info.getType();
    int subType = info.getSubtype();

    if (type == ConnectivityManager.TYPE_WIFI) {
        return false;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return false; // ~ 50-100 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.licubeclub.zionhs.Schedule.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_schedule);

    final TextView MonthTxt = (TextView) findViewById(R.id.month);
    Button Minus = (Button) findViewById(R.id.minus);
    Button Plus = (Button) findViewById(R.id.plus);

    Calendar Cal = Calendar.getInstance();
    month = Cal.get(Calendar.MONTH) + 1;
    year = Cal.get(Calendar.YEAR);

    final int MONTH = month;
    final int YEAR = year;

    MonthTxt.setText(String.valueOf(year) + "." + String.valueOf(month));
    Minus.setOnClickListener(new View.OnClickListener() {
        @Override//from w w w .  j  a v  a 2s  .  c o m
        public void onClick(View v) {
            movement--;
            NewURL = "http://www.zion.hs.kr/main.php?menugrp=020500&master=diary&act=list&master_sid=1&"
                    + "SearchYear=" + YEAR + "&SearchMonth=" + MONTH + "&SearchCategory=&SearchMoveMonth="
                    + movement;
            URL = NewURL;
            networkTask();
            if (month == 1) {
                month = 12;
                year--;
            } else {
                month--;
            }
            MonthTxt.setText(String.valueOf(year) + "." + String.valueOf(month));
        }
    });
    Plus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            movement++;
            NewURL = "http://www.zion.hs.kr/main.php?menugrp=020500&master=diary&act=list&master_sid=1&"
                    + "SearchYear=" + YEAR + "&SearchMonth=" + MONTH + "&SearchCategory=&SearchMoveMonth="
                    + movement;
            URL = NewURL;
            networkTask();
            if (month == 12) {
                month = 1;
                year++;
            } else {
                month++;
            }
            MonthTxt.setText(String.valueOf(year) + "." + String.valueOf(month));
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    listview = (ListView) findViewById(R.id.listView);

    cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    SRL = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    SRL.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            networkTask();
        }
    });

    networkTask();

}

From source file:org.gc.networktester.util.Util.java

public static int getTimingResource(MainActivity mainAct, long timing) {
    if (mainAct.getNetworkType() == null) {
        return 0;
    } else if (mainAct.getNetworkType() == ConnectivityManager.TYPE_MOBILE) {
        if (timing < mobileThresholds[0]) {
            return R.drawable.timing_good;
        } else if (timing < mobileThresholds[1]) {
            return R.drawable.timing_medium;
        } else {/*from ww  w  .  ja  v a2s  . com*/
            return R.drawable.timing_bad;
        }
    } else if (mainAct.getNetworkType() == ConnectivityManager.TYPE_WIFI || mainAct.getNetworkType() == 6) { // ConnectivityManager.TYPE_WIMAX since API level 8
        if (timing < wifiThresholds[0]) {
            return R.drawable.timing_good;
        } else if (timing < wifiThresholds[1]) {
            return R.drawable.timing_medium;
        } else {
            return R.drawable.timing_bad;
        }
    } else {
        Toast.makeText(mainAct, R.string.error_unknown_network_type, Toast.LENGTH_LONG).show();
        return 0;
    }
}

From source file:org.telegram.messenger.GcmPushListenerService.java

@Override
public void onMessageReceived(String from, final Bundle bundle) {
    FileLog.d("GCM received bundle: " + bundle + " from: " + from);
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override/*www . j  a v  a2s. c o m*/
        public void run() {
            ApplicationLoader.postInitApplication();

            try {
                String key = bundle.getString("loc_key");
                if ("DC_UPDATE".equals(key)) {
                    String data = bundle.getString("custom");
                    JSONObject object = new JSONObject(data);
                    int dc = object.getInt("dc");
                    String addr = object.getString("addr");
                    String[] parts = addr.split(":");
                    if (parts.length != 2) {
                        return;
                    }
                    String ip = parts[0];
                    int port = Integer.parseInt(parts[1]);
                    ConnectionsManager.getInstance().applyDatacenterAddress(dc, ip, port);
                } else if ("MESSAGE_ANNOUNCEMENT".equals(key)) {
                    Object obj = bundle.get("google.sent_time");
                    long time;
                    try {
                        if (obj instanceof String) {
                            time = Utilities.parseLong((String) obj);
                        } else if (obj instanceof Long) {
                            time = (Long) obj;
                        } else {
                            time = System.currentTimeMillis();
                        }
                    } catch (Exception ignore) {
                        time = System.currentTimeMillis();
                    }

                    TLRPC.TL_updateServiceNotification update = new TLRPC.TL_updateServiceNotification();
                    update.popup = false;
                    update.flags = 2;
                    update.inbox_date = (int) (time / 1000);
                    update.message = bundle.getString("message");
                    update.type = "announcement";
                    update.media = new TLRPC.TL_messageMediaEmpty();
                    final TLRPC.TL_updates updates = new TLRPC.TL_updates();
                    updates.updates.add(update);
                    Utilities.stageQueue.postRunnable(new Runnable() {
                        @Override
                        public void run() {
                            MessagesController.getInstance().processUpdates(updates, false);
                        }
                    });
                } else if (Build.VERSION.SDK_INT >= 24 && ApplicationLoader.mainInterfacePaused
                        && UserConfig.isClientActivated()) {
                    Object value = bundle.get("badge");
                    if (value == null) {
                        Object obj = bundle.get("google.sent_time");
                        long time;
                        if (obj instanceof String) {
                            time = Utilities.parseLong((String) obj);
                        } else if (obj instanceof Long) {
                            time = (Long) obj;
                        } else {
                            time = -1;
                        }
                        if (time == -1 || UserConfig.lastAppPauseTime < time) {
                            ConnectivityManager connectivityManager = (ConnectivityManager) ApplicationLoader.applicationContext
                                    .getSystemService(Context.CONNECTIVITY_SERVICE);
                            NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
                            if (connectivityManager
                                    .getRestrictBackgroundStatus() == RESTRICT_BACKGROUND_STATUS_ENABLED
                                    && netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                                NotificationsController.getInstance().showSingleBackgroundNotification();
                            }
                        }
                    }
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            ConnectionsManager.onInternalPushReceived();
            ConnectionsManager.getInstance().resumeNetworkMaybe();
        }
    });
}

From source file:dev.ukanth.ufirewall.RulesActivity.java

protected void appendSystemInfo(final Context ctx) {
    // Fourth section: "System info"
    writeHeading(result, true, "System info");

    InterfaceDetails cfg = InterfaceTracker.getCurrentCfg(ctx);

    result.append("Android version: " + android.os.Build.VERSION.RELEASE + "\n");
    result.append("Manufacturer: " + android.os.Build.MANUFACTURER + "\n");
    result.append("Model: " + android.os.Build.MODEL + "\n");
    result.append("Build: " + android.os.Build.DISPLAY + "\n");

    if (cfg.netType == ConnectivityManager.TYPE_MOBILE) {
        result.append("Active interface: mobile\n");
    } else if (cfg.netType == ConnectivityManager.TYPE_WIFI) {
        result.append("Active interface: wifi\n");
    } else {// w  ww  .  j a  va  2s  .  c  o m
        result.append("Active interface: unknown\n");
    }
    result.append(
            "Tether status: " + (cfg.tetherStatusKnown ? (cfg.isTethered ? "yes" : "no") : "unknown") + "\n");
    result.append("Roam status: " + (cfg.isRoaming ? "yes" : "no") + "\n");
    result.append("IPv4 subnet: " + cfg.lanMaskV4 + "\n");
    result.append("IPv6 subnet: " + cfg.lanMaskV6 + "\n");

    // filesystem calls can block, so run in another thread
    new AsyncTask<Void, Void, String>() {
        @Override
        public String doInBackground(Void... args) {
            StringBuilder ret = new StringBuilder();

            ret.append(getFileInfo("/system/bin/su"));
            ret.append(getFileInfo("/system/xbin/su"));
            ret.append(getFileInfo("/system/app/Superuser.apk"));

            PackageManager pm = ctx.getPackageManager();
            ret.append("Superuser: " + getSuInfo(pm));
            ret.append("\n");

            return ret.toString();
        }

        @Override
        public void onPostExecute(String suInfo) {
            result.append(suInfo);
            appendPreferences(ctx);
        }
    }.execute();

}

From source file:com.lance.commu.fragment.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.out.println("base onCreate ");
    // set the Behind View
    setBehindContentView(R.layout.menu_frame);
    if (savedInstanceState == null) {
        FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
        mFrag = new MenuListFragment();
        t.replace(R.id.menu_frame, mFrag);
        t.commit();/*from  w ww  .j a  v  a2s  . c  om*/
    } else {
        mFrag = (ListFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
    }
    // customize the SlidingMenu  
    SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidthRes(R.dimen.shadow_width);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    sm.setFadeDegree(0.35f);
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    sm.setBehindOffset(400);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ////////////////////////////////////////
    connect = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); //  
    requestURL1 = "http://121.157.84.63:8080/lance/androidFriendList.jsp"; //    

    //       
    //  OracleDB    
    //   ListView   
    getContactData();

    //Sqlite DB  
    //Oracle DB   Sqlite  
    //     Oracle DB   
    //Sqlite     
    //      Oracle DB  Sqlite 
    try {
        db_Handler = DB_Handler.open(this);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("db open ");
    }

    //       
    //Oracle DB  
    if (connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED
            || connect.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                    .getState() == NetworkInfo.State.CONNECTED) {
        if (flag == true) {
            new Networking1().execute();
            System.out.println(" ");
            flag = false; //          
                          // Sqlite ListView  
        }

    }

    else {
        Toast toast = Toast.makeText(BaseActivity.this, " ", Toast.LENGTH_SHORT);
        toast.show();
    }

    System.out.println("base onCreate ");
}

From source file:com.tbay.android.tcpclient.MainActivity.java

/**
 * Check whether the device is connected, and if so, whether the connection
 * is wifi or mobile (it could be something else).
 *//*from   w ww  .  j a v a 2  s.co  m*/
private void checkNetworkConnection() {
    // BEGIN_INCLUDE(connect)
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.isConnected()) {
        wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
        mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
        if (wifiConnected) {
            Log.i(TAG, getString(R.string.wifi_connection));
        } else if (mobileConnected) {
            Log.i(TAG, getString(R.string.mobile_connection));
        }
    } else {
        Log.i(TAG, getString(R.string.no_wifi_or_mobile));
    }
    // END_INCLUDE(connect)
}

From source file:com.kentph.ttcnextbus.CreateDatabaseActivity.java

private void updateConnectedFlags() {
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.isConnected()) {
        wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
        mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
    } else {//from   w  w w  .j av  a  2s  .  c om
        wifiConnected = false;
        mobileConnected = false;
    }
}

From source file:com.mediatek.engineermode.EngineerMode.java

private boolean isWifiOnly() {
    ConnectivityManager connManager = (ConnectivityManager) EngineerMode.this
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean bWifiOnly = false;
    if (null != connManager) {
        bWifiOnly = !connManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
        Log.i("@M_" + TAG, "bWifiOnly: " + bWifiOnly);
    }/*  w w w  .  java  2  s.  c o m*/
    return bWifiOnly;
}

From source file:org.wso2.emm.agent.services.DeviceNetworkStatus.java

/**
 * Network data such as  connection type and signal details can be fetched with this method.
 *
 * @return String representing network details.
 * @throws AndroidAgentException/*from ww w.j a  v a 2s  .com*/
 */
public String getNetworkStatus() throws AndroidAgentException {
    info = getNetworkInfo(this.context);
    String payload = null;
    if (info != null) {
        List<Device.Property> properties = new ArrayList<>();
        Device.Property property = new Device.Property();
        property.setName(Constants.Device.CONNECTION_TYPE);
        property.setValue(info.getTypeName());
        properties.add(property);

        if ((info.isConnected())) {
            if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                property = new Device.Property();
                property.setName(Constants.Device.MOBILE_CONNECTION_TYPE);
                property.setValue(info.getSubtypeName());
                properties.add(property);
            }
            if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                property = new Device.Property();
                property.setName(Constants.Device.WIFI_SSID);
                // NetworkInfo API of Android seem to add extra "" to SSID, therefore escaping it.
                property.setValue(String.valueOf(getWifiSSID()).replaceAll("\"", ""));
                properties.add(property);

                property = new Device.Property();
                property.setName(Constants.Device.WIFI_SIGNAL_STRENGTH);
                property.setValue(String.valueOf(getWifiSignalStrength()));
                properties.add(property);

            }
        }

        property = new Device.Property();
        property.setName(Constants.Device.MOBILE_SIGNAL_STRENGTH);
        property.setValue(String.valueOf(getCellSignalStrength()));
        properties.add(property);

        try {
            payload = mapper.writeValueAsString(properties);
        } catch (JsonProcessingException e) {
            String errorMsg = "Error occurred while parsing " + "network property property object to json.";
            Log.e(TAG, errorMsg, e);
            throw new AndroidAgentException(errorMsg, e);
        }
    }
    return payload;
}