如何在连接WIFI时关闭应用程序?

时间:2016-03-28 08:23:10

标签: android

最近我点击wifi连接按钮。 显示Connectreceiver.class(活动)

我想完成wifi连接(=连接状态)

完成app(=杀死app)

我该怎么办?

public class Connectingreceiver extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        setContentView(R.layout.connecting_dialog);

  registerReceiver(progressFinish, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
    }
private BroadcastReceiver progressFinish = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();


        ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if(action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
            if(networkInfo.getState()== NetworkInfo.State.CONNECTED){
                moveTaskToBack(true);
                finish();
                android.os.Process.killProcess(android.os.Process.myPid());
            }
        }

    }





};
@Override
protected void onPause(){
    super.onPause();
    try{
        unregisterReceiver(progressFinish);
    } catch (IllegalArgumentException e){
        e.printStackTrace();
    }
}

}

0 个答案:

没有答案