CopyPastor

Detecting plagiarism made easy.

Score: 0.8456785320111629; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-12-11
by Pruthwi RS

Original Post

Original - Posted on 2014-03-10
by Adnan



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You will need to use broadcast receiver. You will continuously receive updates in connectivity.(Connected/Disconnected) Example: Manifest: Permissions: <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> Register broadcast receiver: <receiver android:name=".ConnectivityChangeReceiver" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> Create receiver class: public class ConnectivityChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Explicitly specify that which service class will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), YourService.class.getName()); intent.putExtra("isNetworkConnected",isConnected(context)); startService(context, (intent.setComponent(comp))); } public boolean isConnected(Context context) { ConnectivityManager connectivityManager = ((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected(); } } Your service class: class YourService extends IntentService{ @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); boolean isNetworkConnected = extras.getBoolean("isNetworkConnected"); // your code } }
You might need to use broadcast receiver. You will continuously receive updates in connectivity.(Connected/Disconnected)
Example:
**Manifest:**
Permissions:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Register broadcast receiver:
<receiver android:name=".ConnectivityChangeReceiver" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> **Create receiver class:**
public class ConnectivityChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Explicitly specify that which service class will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), YourService.class.getName()); intent.putExtra("isNetworkConnected",isConnected(context)); startService(context, (intent.setComponent(comp))); } public boolean isConnected(Context context) { ConnectivityManager connectivityManager = ((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected(); } }
**Your service class:**
class YourService extends IntentService{ @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); boolean isNetworkConnected = extras.getBoolean("isNetworkConnected"); // your code } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;