package com.testing.connection; import android.app.Activity; import android.net.ConnectivityManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class ConnectionActivity extends Activity implements OnClickListener{ Button press; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); press = (Button)findViewById(R.id.button1); press.setOnClickListener(this); } public void onClick(View view){ ConnectivityManager mgr = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); boolean is3G = mgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); boolean isWifi = mgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting(); if(isWifi){ Toast.makeText(this, "WiFi connected...", Toast.LENGTH_LONG).show(); sendMail(); } else{
Hi, I am developing an Android application, and I would like to have the function of automatically turning on mobile data after detecting Wi-Fi that is not connected to the phone, because I would like to make sure that the message can be sent whether Wi-Fi is connected or not ... So, when Wi-Fi is detected not connected, 3G data is turned on and an email is sent, and the data network is disconnected ...
Can I learn how to rotate a 3G network and disconnect a 3G network ??? The Internet source is sparse, and I hope someone can help me solve it ... Thanks ...
source share