Skip to content

Commit

Permalink
Merge pull request #1570 from SunJiashun/master
Browse files Browse the repository at this point in the history
#7 SunJiashun 实验七控制和检测网络
  • Loading branch information
zengsn authored Apr 23, 2019
2 parents ae6e055 + e3e3f42 commit 3958ac0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CarinfoActivity extends AppCompatActivity {
private Button btn_collect;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package soft1509081602625.androidlabs.hzuapps.edu.soft1509081602625activity;

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 ConnectionUtil {
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();
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package soft1509081602625.androidlabs.hzuapps.edu.soft1509081602625activity;
package soft1509081602625.androidlabs.hzuapps.edu.soft1509081602625activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import soft1714080902407.androidlabs.hzuapps.edu.soft1509081602625activity.R;

Expand All @@ -14,15 +16,23 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1509081602625_activity);
}

@Override
protected void onStart(){
Log.i("Soft1509081602625Actvity","onStart");
if(!ConnectionUtil.isConn(this)){
ConnectionUtil.setNetworkMethod(this);
}else{
Toast.makeText(this, "当前网络可用", Toast.LENGTH_SHORT).show();
}
super.onStart();
}
public void onClick(View view) {
Intent intent = new Intent(Soft1509081602625Activity.this, CarinfoActivity.class);
startActivity(intent);
}

public void onClick3 (View view){
Intent intent = new Intent(Soft1509081602625Activity.this, MyCollectionActivity.class);
startActivity(intent);
}
};
public void onClick3 (View view){
Intent intent = new Intent(Soft1509081602625Activity.this, MyCollectionActivity.class);
startActivity(intent);
};
}

0 comments on commit 3958ac0

Please sign in to comment.