如何增加收益率=在无线设置真 [英] how to add return=true in wireless settings
问题描述
即时通讯工作的一个项目,并即时通讯卡,我想是使无线或互联网,后退按钮(硬件按钮)后,应该把我带回 SplitScreen.xml
而不是关闭应用程序,请不要给任何code加,因为我的code工作正常,insted的,纠正我的code
im working on a project and im stuck, what i want is after enabling wifi or internet, the back button(hardware button) should bring me back to SplitScreen.xml
instead of closing the app please dont give any code to add , as my code is working fine , insted ,correct my code
}}
推荐答案
要实现你想要的行为,将您的来电,打开无线设置的MainActivity,和一个布尔变量添加到它的意图,指示设置是否应在MainActivity.onCreate开业。
To achieve the behavior you want, move your call to open Wireless Settings to the MainActivity, and add a boolean variable to its Intent to indicate whether the Settings should be opened in MainActivity.onCreate.
总重做修改
这是你的SplashActivity.java。你应该有唯一的问题就是布局名。我不记得你把它命名。
This is your SplashActivity.java. The only problem you should have is the layout name. I don't remember what you named it.
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog.OnClickListener;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class SplashScreen extends Activity
{
static ConnectivityManager cm;
AlertDialog dailog;
AlertDialog.Builder build;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);// checking
build = new AlertDialog.Builder(this);
setContentView(R.layout.activity_splash);
// if connection is
// there screen goes
// to next screen
// else shows
// message
if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()
|| cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting())
{
Log.e("cm value", "" + cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.isConnectedOrConnecting());
Toast.makeText(this, "Internet is active", 2000).show();
Thread mythread = new Thread() {
public void run()
{
try
{
sleep(5000);
}
catch (Exception e)
{
}
finally
{
Intent intent = new Intent(SplashScreen.this,
MainActivity.class);
startActivity(intent);
finish();
}
}
};
mythread.start();
}
else
{
build.setMessage("This application requires Internet connection. Would you connect to internet ?");
build.setPositiveButton("Yes", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
Intent intent = new Intent(SplashScreen.this,
MainActivity.class);
intent.putExtra("showSettings", true);
startActivity(intent);
finish();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
});
build.setNegativeButton("No", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
build.setMessage("Are sure you want to exit?");
build.setPositiveButton("Yes", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
}
});
build.setNegativeButton("NO", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
Intent intent = new Intent(SplashScreen.this,
SplashScreen.class);
startActivity(intent);
dialog.dismiss();
}
});
dailog = build.create();
dailog.show();
}
});
dailog = build.create();
dailog.show();
}
}
}
这是你的MainActivity。
And this is your MainActivity.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.Toast;
public class MainActivity extends Activity
{
ToggleButton toggle;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggle = (ToggleButton)findViewById(R.id.tglbtn1);
toggle.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (toggle.isChecked())
{
Toast.makeText(getApplicationContext(), "Boosting For Next 60 Minutes, Minimize the Application", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Boosting Turned Off", Toast.LENGTH_LONG).show();
}
}
}
);
Intent intent = getIntent();
boolean show = intent.getBooleanExtra("showSettings", false);
if (show)
{
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
}
}
修正了闪屏布局名称的问题,您应该不错。我只是跑这个code和性能达到要求。
Fix the layout name issue in SplashScreen and you should be good. I just ran this code and it performs as expected.
这篇关于如何增加收益率=在无线设置真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!