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:com.zhiyicx.zycx.sociax.gimgutil.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing
 * logic). A memory and disk cache will be used if an {@link ImageCache} has
 * been set using {@link ImageWorker#setImageCache(ImageCache)}. If the
 * image is found in the memory cache, it is set immediately, otherwise an
 * {@link AsyncTask} will be created to asynchronously load the bitmap.
 *
 * @param data      The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//*from  w w w .j  a  v  a  2  s  .c  om*/
public void loadImage(Object data, ImageView imageView, String type) {

    if (SociaxUIUtils.getNetworkType(mContext) == ConnectivityManager.TYPE_MOBILE) {

        /*System.out.println("is download image setting "
            + SettingsActivity.isDownloadPic(mContext));
                
        if (!SettingsActivity.isDownloadPic(mContext)) {
           System.out.println("is download image setting "
          + SettingsActivity.isDownloadPic(mContext));
           return;
        }*/
    }

    if (data == null) {
        return;
    }

    Bitmap bitmap = null;

    if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (bitmap != null) {
        // Bitmap found in memory cache
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been
        // pulled from the
        // framework and slightly modified. Refer to the docs at the top of
        // the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data);
    }
}

From source file:hobby.wei.c.phone.Network.java

public static boolean isRoaming(Context context) {
    NetworkInfo networkInfo = getConnectManager(context).getActiveNetworkInfo();
    boolean isMobile = (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
    boolean isRoaming = isMobile && getTelephonyManager(context).isNetworkRoaming();
    return isRoaming;
}

From source file:com.abcs.sociax.gimgutil.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing
 * logic). A memory and disk cache will be used if an {@link ImageCache} has
 * been set using {@link ImageWorker#setImageCache(ImageCache)}. If the
 * image is found in the memory cache, it is set immediately, otherwise an
 * {@link AsyncTask} will be created to asynchronously load the bitmap.
 * /*from w w  w. ja va  2 s  .c  o  m*/
 * @param data
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public void loadImage(Object data, ImageView imageView, String type) {

    if (SociaxUIUtils.getNetworkType(mContext) == ConnectivityManager.TYPE_MOBILE) {

        System.out.println("is download image setting " + SettingsActivity.isDownloadPic(mContext));

        if (!SettingsActivity.isDownloadPic(mContext)) {
            System.out.println("is download image setting " + SettingsActivity.isDownloadPic(mContext));
            return;
        }
    }

    if (data == null) {
        return;
    }

    Bitmap bitmap = null;

    if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (bitmap != null) {
        // Bitmap found in memory cache
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been
        // pulled from the
        // framework and slightly modified. Refer to the docs at the top of
        // the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data);
    }
}

From source file:com.example.android.networkbasic.MainActivity.java

/**
 * Check whether the device is connected, and if so, whether the connection
 * is wifi or mobile (it could be something else).
 *///from ww w .j  a  v a  2 s  .co m
private void checkNetworkConnection() {

    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));
    }

}

From source file:com.commonsware.android.webserver.WebServerService.java

@Override
public void onCreate() {
    super.onCreate();

    ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo ni = mgr.getActiveNetworkInfo();

    if (ni == null || ni.getType() == ConnectivityManager.TYPE_MOBILE) {
        EventBus.getDefault().post(new ServerStartRejectedEvent());
        stopSelf();/*from w  w w .  ja  v  a  2s  . com*/
    } else {
        handlebars = new Handlebars(new AssetTemplateLoader(getAssets()));
        rootPath = "/" + new BigInteger(20, rng).toString(24).toUpperCase();

        server = new AsyncHttpServer();

        if (configureRoutes(server)) {
            server.get("/.*", new AssetRequestCallback());
        }

        server.listen(getPort());

        raiseReadyEvent();
        foregroundify();
        timeoutFuture = timer.schedule(onTimeout, getMaxIdleTimeSeconds(), TimeUnit.SECONDS);
    }
}

From source file:com.example.android.basicnetworking.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  w w  . ja va2 s  . co  m*/
private void checkNetworkConnection() {
    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));
    }
}

From source file:cc.psdev.heywifi.MainService.java

@Override
public void run() {
    while (true) {
        loadDB();/*from   w  w  w  .j av  a2  s  .  com*/

        if (shouldRun()) {
            showTurnedoffNoti(0);

            searchWifi();

            autoonstatus = autoOn();
            if (!autoonstatus && pref.getOffOutofRange() == 1) {
                wm.setWifiEnabled(false);
                if (pref.getOffOutofRangeData() == 1) {
                    if (SDK_VERSION > SDK_21) {
                        // TODO: find how to disable mobile network on lollipop and above
                    } else {
                        cm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
                                "android.net.conn.CONNECTIVITY_CHANGE");
                    }
                }
            }
            if (!changeRingmode() && pref.getRingmodeSaveEnabled() == 1 && pref.getRingmodeSaved() != -1) {
                changeFromSavedRingmode(pref.getRingmodeSaved() - 10);
                pref.putRingmodeSaved(-1);
            }

            if (autoonstatus && pref.getOffData() == 1) {
                if (SDK_VERSION > SDK_21) {
                    // TODO: same as up
                } else {
                    cm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
                            "android.net.conn.CONNECTIVITY_CHANGE");
                }
            }
        } else {
            showTurnedoffNoti(1);
        }

        try {
            Thread.sleep(sleepTime - 2000);
        } catch (InterruptedException ex) {
        }
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Calendar Cal = Calendar.getInstance();
    AMorPM = Cal.get(Calendar.AM_PM);
    DAYofWEEK = Cal.get(Calendar.DAY_OF_WEEK);
    DAYofMONTH = Cal.get(Calendar.DAY_OF_MONTH);

    Log.d("DAYofMONTH", String.valueOf(Cal.get(Calendar.DAY_OF_MONTH)));

    cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    setContentView(R.layout.activity_main);

    /*// ww  w  .j a  v a2  s.  co m
    * TODO - ?    (/?/?)
    * */
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    MEAL = (TextView) findViewById(R.id.mealdata);
    SCHEDULE = (TextView) findViewById(R.id.schedata);
    NOTIPARNTS = (TextView) findViewById(R.id.notiparentdata);
    NOTICES = (TextView) findViewById(R.id.notidata);

    View notices = findViewById(R.id.notices);
    View meal = findViewById(R.id.meal);
    View schedule = findViewById(R.id.schedule);
    View notices_parents = findViewById(R.id.notices_parents);

    notices.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent0 = new Intent(MainActivity.this, Notices.class);
            intent0.putExtra("url",
                    "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=58");
            intent0.putExtra("title", getResources().getString(R.string.notices));
            startActivity(intent0);
        }
    });

    meal.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, MealActivity.class);
            startActivity(intent);
        }
    });

    schedule.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, Schedule.class);
            startActivity(intent);
        }
    });

    notices_parents.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, Notices.class);
            intent.putExtra("url",
                    "http://www.zion.hs.kr/main.php?menugrp=110200&master=bbs&act=list&master_sid=59");
            intent.putExtra("title", getResources().getString(R.string.title_activity_notices__parents));
            startActivity(intent);
        }
    });

    //Navigation Drawer
    DrawerArray = new ArrayList<String>();
    DrawerArray.add(getString(R.string.meal));
    DrawerArray.add(getString(R.string.schedule));
    DrawerArray.add(getString(R.string.title_activity_notices__parents));
    DrawerArray.add(getString(R.string.notices));
    DrawerArray.add(getString(R.string.schoolintro));
    DrawerArray.add(getString(R.string.schoolinfo));
    DrawerArray.add(getString(R.string.appsettings_apinfo_title));

    IconArray = new ArrayList<Drawable>();
    IconArray.add(getResources().getDrawable(R.drawable.ic_meal));
    IconArray.add(getResources().getDrawable(R.drawable.ic_event_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_insert_drive_file_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_speaker_notes_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_intro));
    IconArray.add(getResources().getDrawable(R.drawable.ic_school));
    IconArray.add(getResources().getDrawable(R.drawable.ic_info_black_24dp));

    NavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    DrawerList = (ListView) findViewById(R.id.left_drawer);

    Adapter = new DrawerListAdapter(this, DrawerArray, IconArray);
    DrawerList.setAdapter(Adapter);

    //Listen for Navigation Drawer State
    DrawerToggle = new ActionBarDrawerToggle(this, NavigationDrawer, R.string.drawer_open,
            R.string.drawer_close) {
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            isNavDrawerOpen = false;
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //                getSupportActionBar().setBackgroundDrawable(Darkblue);
            isNavDrawerOpen = true;
        }

    };
    NavigationDrawer.setDrawerListener(DrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    //Drawer Item Click action
    DrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                startActivity(new Intent(MainActivity.this, MealActivity.class));
                break;
            case 1:
                startActivity(new Intent(MainActivity.this, Schedule.class));
                break;
            case 2:
                Intent intent = new Intent(MainActivity.this, Notices.class);
                intent.putExtra("url",
                        "http://www.zion.hs.kr/main.php?menugrp=110200&master=bbs&act=list&master_sid=59");
                intent.putExtra("title", getResources().getString(R.string.title_activity_notices__parents));
                startActivity(intent);
                break;
            case 3:
                Intent intent0 = new Intent(MainActivity.this, Notices.class);
                intent0.putExtra("url",
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=58");
                intent0.putExtra("title", getResources().getString(R.string.notices));
                startActivity(intent0);
                break;
            case 4:
                startActivity(new Intent(MainActivity.this, Schoolintro.class));
                break;
            case 5:
                startActivity(new Intent(MainActivity.this, Schoolinfo.class));
                break;
            case 6:
                startActivity(new Intent(MainActivity.this, Appinfo.class));
                break;
            }
        }
    });

    SRL = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    if (mobile.isConnected() || wifi.isConnected()) {
        networkTask();
    } else {

        Toast toast = Toast.makeText(getApplicationContext(),
                getResources().getString(R.string.network_connection_warning), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();
    }
    SRL.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if (mobile.isConnected() || wifi.isConnected()) {
                networkTask();
            } else {

                Toast toast = Toast.makeText(getApplicationContext(),
                        getResources().getString(R.string.network_connection_warning), Toast.LENGTH_LONG);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
                SRL.setRefreshing(false);
            }
        }
    });

}

From source file:com.frame.network.utils.NetworkUtil.java

@TargetApi(11)
public static boolean is4GNetwork(Context cxt) {
    boolean isOpened4G = false;
    TelephonyManager telephonyManager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= 11) {
        isOpened4G = telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE;
    }//from w w w  .j a  v a 2s.  c  om
    boolean isMobile = false;
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    isMobile = info == null ? false : info.isConnected();
    return isOpened4G && isMobile;
}

From source file:com.OpenSource.engine.connectivity.ConnectivityInfoProvider.java

public boolean isMobileConnected() {
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return false;
    }//www.  j  ava2  s.c  om
    return networkInfo.getState() == NetworkInfo.State.CONNECTED
            && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
}