【发布时间】:2015-07-01 13:16:46
【问题描述】:
我正在尝试创建一个Dialog,它显示类似ACTION_PICK_WIFI_NETWORK 的内容,但不是打开Android Settings / WiFi,而是在Dialog 上打开它,如果可能,用户可以连接到该Dialog 可用的任何网络.我目前正在打开一个Dialog 和一个List 在Android 中可用的Wi-Fi 网络,但是这个List 与Android Settings / WiFi 不同,这就是为什么我要问它是否可能在对话框中打开此ACTION_PICK_WIFI_NETWORK 并使用它。如果不可能,我怎么能连接到网络,点击我的Dialog 中的Item 并提供 WiFi?
到目前为止我尝试过的是
我有一个BroadcastReceiver()
wifiReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context c, Intent intent){
if(mWifiManager != null) {
List<ScanResult> results = mWifiManager.getScanResults();
showWifiListDialog(results);
}
}
};
RegisterReceiver()
registerReceiver(wifiReceiver,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
这是执行WifiScan的方法
private void startWifiScans() {
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
mWifiManager.startScan();
}
这是简单的Dialog,它显示SCAN_RESULTS_AVAILABLE_ACTION
private void showWifiListDialog(List<ScanResult> results) {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(
this);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
this,
android.R.layout.select_dialog_item);
for (ScanResult r: results) {
if(r == null || r.SSID == null) continue;
if("".equalsIgnoreCase(r.SSID.trim())) continue;
String name = r.SSID.replace("\"", "");
arrayAdapter.add(name);
}
builderSingle.setNegativeButton(getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
Toast.makeText(getApplicationContext(),"Selected "+strName, Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = builderSingle.create();
dialog.show();
}
图片示例
编辑(这就是我现在看到我的Dialog,但我还不喜欢它......)
我想展示带有icon 的网络,其信号强度类似于android 的example。我想我需要一个 ListAdapter 左右?然后添加网络名称、强度连接、图标等...我错了吗?
几乎是同一个问题there..
我想通过Notification 打开它,显然我是在那个 APP 还是其他 APP 上都没关系...我只想将它作为一个对话框打开,让用户看看用户正在观看。
现在我得到的是:
我正在使用Theme,但它并没有达到我想要的效果。
<style name="dialogtest" parent="AppTheme">
<item name="android:windowFrame">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
这就是风格,我称之为这样做:
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.dialogtest);
super.onCreate(savedInstanceState);
【问题讨论】:
-
我会对此进行调查并回复您。我以前没有这样做过...... :)
-
好的,我已经编辑了我的答案并解释了更多。
-
抱歉耽搁了。我一直忙于工作...... :(我理解你的问题。
-
到目前为止,我还无法弄清楚这是如何做到的......
-
没关系...我想我会放一个赏金来看看aomeone是否可以帮助我:)
标签: android