-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1573 from wufchun/master
- Loading branch information
Showing
6 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
...902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/ConnectionNetwork.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package edu.hzuapps.androidlabs.soft1714080902414; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
|
||
public class ConnectionNetwork { | ||
//判断网络连接是否已开 | ||
public static boolean isConn(Context context) { | ||
boolean bisConnFlag = false; | ||
ConnectivityManager conManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
NetworkInfo network = conManager.getActiveNetworkInfo(); | ||
if (network != null) { | ||
bisConnFlag = conManager.getActiveNetworkInfo().isAvailable(); | ||
} | ||
return bisConnFlag; | ||
} | ||
//打开网络设置界面 | ||
public static void setNetworkMethod(final Context context){ | ||
//提示对话框 | ||
AlertDialog.Builder builder=new AlertDialog.Builder(context); | ||
builder.setTitle("网络设置提示").setMessage("网络连接不可用,是否进行设置?").setPositiveButton("设置", new DialogInterface.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// TODO Auto-generated method stub | ||
Intent intent=null; | ||
//判断手机系统的版本 即API大于10 就是3.0或以上版本 | ||
if(android.os.Build.VERSION.SDK_INT>10){ | ||
intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); | ||
}else{ | ||
intent = new Intent(); | ||
ComponentName component = new ComponentName("com.android.settings","com.android.settings.WirelessSettings"); | ||
intent.setComponent(component); | ||
intent.setAction("android.intent.action.VIEW"); | ||
} | ||
context.startActivity(intent); | ||
} | ||
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// TODO Auto-generated method stub | ||
dialog.dismiss(); | ||
} | ||
}).show(); | ||
} | ||
} |
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
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
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
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