Created
January 6, 2015 03:46
-
-
Save code4lifevn/00d4083e70cc9d63c9b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.test" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<uses-sdk android:minSdkVersion="8"/> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> | |
<activity android:name="MyActivity" | |
android:label="@string/app_name"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
<receiver android:name=".NetworkReceiver"> | |
<intent-filter> | |
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.test; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
/** | |
* Created by SexyBoyHaha on 1/6/2015. | |
*/ | |
public class NetworkReceiver extends BroadcastReceiver { | |
private static boolean isRunning = true; | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
final NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); | |
if (activeNetInfo != null) { | |
if(isRunning) { | |
System.out.println("FAP"); | |
// do subroutines here | |
isRunning = false; | |
} | |
} | |
else { | |
isRunning = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment