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
// Listener to update the UI upon connectionclass change. | |
private class ConnectionChangedListener | |
implements ConnectionClassManager.ConnectionClassStateChangeListener { | |
@Override | |
public void onBandwidthStateChange(ConnectionQuality bandwidthState) { | |
mConnectionClass = bandwidthState; | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { |
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
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mConnectionClassManager = ConnectionClassManager.getInstance(); | |
mDeviceBandwidthSampler = DeviceBandwidthSampler.getInstance(); | |
} |
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
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url("IMAGE_URL_HERE") | |
.build(); | |
mDeviceBandwidthSampler.startSampling(); | |
client.newCall(request).enqueue(new Callback() { | |
@Override | |
public void onFailure(Request request, IOException e) { | |
e.printStackTrace(); |
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
private ConnectionQuality mConnectionClass = ConnectionQuality.UNKNOWN; | |
private ConnectionClassManager mConnectionClassManager; | |
private DeviceBandwidthSampler mDeviceBandwidthSampler; | |
private ConnectionChangedListener mListener; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |
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
compile 'com.facebook.network.connectionclass:connectionclass:1.0.1' |
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
NetworkInfo info = Connectivity.getNetworkInfo(context); | |
if(info.getType() == ConnectivityManager.TYPE_WIFI){ | |
// do something | |
} else if(info.getType() == ConnectivityManager.TYPE_MOBILE){ | |
// check NetworkInfo subtype | |
if(info.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS){ | |
// Bandwidth between 100 kbps and below | |
} else if(info.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE){ | |
// Bandwidth between 50-100 kbps | |
} else if(info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_0){ |
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
NetworkInfo info = Connectivity.getNetworkInfo(context); | |
if(info.getType() == ConnectivityManager.TYPE_WIFI){ | |
} else if(info.getType() == ConnectivityManager.TYPE_MOBILE){ | |
// check NetworkInfo subtype | |
} |
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
compile 'com.squareup.okhttp3:okhttp:3.3.0' | |
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
long startTime; | |
long endTime; | |
long fileSize; | |
OkHttpClient client = new OkHttpClient(); | |
// bandwidth in kbps | |
private int POOR_BANDWIDTH = 150; | |
private int AVERAGE_BANDWIDTH = 550; | |
private int GOOD_BANDWIDTH = 2000; |
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
<?php | |
$url = "https://fcm.googleapis.com/fcm/send"; | |
$values = array(); | |
$values ['title'] = "This is my message title"; | |
$values ['body'] = "This is my message body"; | |
$data = array(); | |
$data ['to'] = "/topics/news"; | |
$data ['data'] = $values; |