Android Studio not completing widget code
- By Tony Gabriel
- Android Development
- 1 Replies
Figured it out in AS its stfull and stless
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
package com.example.bla;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkSuggestion;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private WifiManager wifiManager;
private ListView listView;
private Button buttonScan;
private int size = 0;
private List<ScanResult> results;
private ArrayList<String> arrayList = new ArrayList<String>();
private ArrayAdapter adapter;
private int REQUEST_LOCATION = 101;
private EditText input;
private AlertDialog ad;
private int ItemNumb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonScan = findViewById(R.id.scanBtn);
buttonScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
scanWifi();
}
});
listView = findViewById(R.id.wifilist);
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
Toast.makeText(this, "Wifi is disabled... Enabling it", Toast.LENGTH_LONG).show();
wifiManager.setWifiEnabled(true);
}
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(adapter);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
alertBuilder.setTitle("Connect to network?");
alertBuilder.setMessage("Please enter network password");
input = new EditText(MainActivity.this);
alertBuilder.setView(input);
alertBuilder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
connectToNetwork("\"" + results.get(ItemNumb).SSID.toString() + "\"", input.getText().toString());
}
});
alertBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
ad = alertBuilder.create();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ItemNumb = I;
ad.show();
}
});
//IntentFilter intentFilter = new IntentFilter();
//intentFilter.addAction("android.net.wifi.SCAN_RESULTS");
//registerReceiver(wifiReceiver, intentFilter);
}
private void scanWifi() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_WIFI_STATE}, REQUEST_LOCATION);
}
arrayList.clear();
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifiManager.startScan();
Toast.makeText(this, "Scanning Wifi...", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length == 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), permissions[0] + " permission refused", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), permissions[0] + " permission granted", Toast.LENGTH_SHORT).show();
}
}
BroadcastReceiver wifiReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
results = wifiManager.getScanResults();
unregisterReceiver(this);
for (ScanResult scanResult : results) {
arrayList.add(scanResult.SSID + " - " + scanResult.capabilities);
adapter.notifyDataSetChanged();
}
}
};
private void connectToNetwork(String networkSSID, String networkPass)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
WifiNetworkSuggestion networkSuggestion1 =
new WifiNetworkSuggestion.Builder()
.setSsid(networkSSID)
.setWpa2Passphrase(networkPass)
.build();
WifiNetworkSuggestion networkSuggestion2 =
new WifiNetworkSuggestion.Builder()
.setSsid(networkSSID)
.setWpa3Passphrase(networkPass)
.build();
List<WifiNetworkSuggestion> suggestionsList = new ArrayList<>();
suggestionsList.add(networkSuggestion1);
suggestionsList.add(networkSuggestion2);
wifiManager.addNetworkSuggestions(suggestionsList);
}
else
{
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = String.format("\"%s\"", networkSSID);
wifiConfiguration.preSharedKey = String.format("\"%s\"", networkPass);
int wifiID = wifiManager.addNetwork(wifiConfiguration);
wifiManager.enableNetwork(wifiID, true);
}
}
}
Or go into settings and disable wifi text and calling.turn off wifi on the simless phone.
Added with my ex-building into a different url, Just remember we are all kind souls.You might always be on someone else's site. even if you are operating your own stuff, e.g. like the Parler social network was using AWS, but then Amazon kicked them out.
.