당신은`setRequiredNetworkType (JobInfo.NETWORK_TYPE_ANY)`와``setRequiredNetworkType (JobInfo.NETWORK_TYPE_NONE)`와 JobInfo` 다른를 만드는 NetworkChangeReceiver
public class NetworkChangeReceiver extends BroadcastReceiver {
private static final String LOG_TAG = "NetworkChangeReceiver";
private boolean isConnected = false;
Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(LOG_TAG, "Receieved notification about network status");
isNetworkAvailable(context);
mContext=context;
}
public boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
if (!isConnected) {
Log.v(LOG_TAG, "Now you are connected to Internet!");
Toast.makeText(context, R.string.internet_available, Toast.LENGTH_SHORT).show();
isConnected = true;
}
return true;
}
}
}
}
Log.v(LOG_TAG, "You are not connected to Internet!");
Toast.makeText(context, R.string.internet_not_available, Toast.LENGTH_SHORT).show();
isConnected = false;
return false;
}
당신이 봤어 사용할 수 있습니까? –
휴대 전화의 변경 사항은 매우 자주 발생합니다. 사용자가 휴대 전화를 매우 바쁘게 사용할 수 없게 될 수도 있습니다. – apelsoczi
@ JaredRummler NETWORK_TYPE_NONE은 자신이 생각하는대로하지 않습니다. 기본적으로 의미가 아니라 네트워크 연결의 종류에 관계없이이 작업을 실행하는 것입니다. 네트워크가없는 경우에만이 작업을 수행하십시오. –