gpt4 book ai didi

Android:设置wifi后返回App

转载 作者:行者123 更新时间:2023-11-29 21:10:58 26 4
gpt4 key购买 nike

在 myActivity 中,这是我用来检查我的手机是否连接到互联网的代码。

if (!isConnected()) {
// super.playingVideo.setVideoUrl(product.getVideoUrl());
String message = getResources().getString(R.string.wifi_prompt);
super.showDialog(this, message, R.string.wifi_setting,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
if (dialog != null) {
dialog.dismiss();
}
currentProduct = product;
isViewRequest = true;
startActivity(new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS));

}
}, R.string.back, dismissDialogListener);
} else {...}

简历:

@Override
protected void onResume() {
// After setting wifi
if (isViewRequest) {
...//mycode
}
super.onResume();
}

我的问题是,当我完成 wifi 连接设置并按下后退按钮时。它返回到我手机的菜单屏幕,而不是恢复 myActivity。只有在那之后我再次启动我的应用程序时,才会执行 onResume() 函数。
那么,设置 wifi 后我想回到我的应用程序是什么?

最佳答案

我认为这是你的答案,你必须打开设置为 ActivityForResult :

startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), 0);

您可以像这样在 AlertDialog 中实现它:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(
this);

// Setting Dialog Title
alertDialog.setTitle("Confirm...");

// Setting Dialog Message
alertDialog.setMessage("Do you want to go to wifi settings?");

// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.ic_launcher);

// Setting Positive "Yes" Button
alertDialog.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

// Activity transfer to wifi settings
startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), 0);
}
});

// Setting Negative "NO" Button
alertDialog.setNegativeButton("no",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event

dialog.cancel();
}
});

// Showing Alert Message
alertDialog.show();

关于Android:设置wifi后返回App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22882479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com