当您尝试使用 Google play 但碰巧未连接到 wifi 网络时,Google play 会执行此操作。
我正在尝试做的事情的照片:
如果你只是运行一个标准
startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
然后它会加载我正在寻找的窗口。但是,我想要一个“后退”和“下一步”按钮覆盖在它上面。 Back 应该返回到前一个窗口,next 应该只有在选择了网络并执行身份验证(如果需要)时才可选择。然后它会转到另一个 Activity 。
我尝试用 fragment 实现它(一个用于 Intent 启动的窗口,另一个用于按钮),但它不起作用。
这是在应用启动时启动的代码
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layfile);
// Intent n = new Intent(this,Pactivity.class);
// startActivity(n);
//
}
}
public class Pactivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
//addPreferencesFromIntent(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
setContentView(R.layout.main);
}
}
public class Pfrag extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
这是xml文件
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference
android:key="key"
android:title="WiFi"
android:summary="Calls WiFi">
<intent android:action="android.net.wifi.PICK_WIFI_NETWORK"/>
</Preference>
</PreferenceScreen>
我还尝试了一些基于首选项的类。也没有按照我的意愿去做。
如何使用 WifiManager.ACTION_PICK_WIFI_NETWORK
将按钮叠加到您看到的内容上?
最佳答案
Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
intent.putExtra("only_access_points", true);
intent.putExtra("extra_prefs_show_button_bar", true);
intent.putExtra("wifi_enable_next_on_connect", true);
startActivityForResult(intent, 1);
这应该可以做到。 从谷歌代码逆向工程。
关于android - 如何在 'back' 窗口上叠加 'next' 和 "pick wifi network "按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11215473/