One 、 Demand analysis

Recently, the computer needs to be connected WiFi, But found WiFi I forgot the password . And there's something saved in the phone WiFi password , But I can't see it in the setting interface of the mobile phone .

Although there are already some to see WiFi Cryptographically app, But the main concern is that the password will be destroyed by those app Send it backstage . It's better to write one by yourself . Also used app Just one click to see , It's more convenient than directly looking up the file in the system where the password is stored .

Two 、 Main function realization

2.1 Read system files

Android The system saved it WiFi The password file is saved in /data/misc/wifi/wpa_supplicant.conf in [1], By running a command line program in code ‘cat’ To read the file [3][4].

String commandResult=commandForResult("cat /data/misc/wifi/wpa_supplicant.conf");
public String commandForResult(String command) { try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = null;
outputStream = new DataOutputStream(process.getOutputStream());
outputStream.writeBytes(command+"\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder total = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
total.append(line);
total.append("\n");
}
return total.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}

2.2 Yes WiFi Information according to priority Sort from big to small

wpa_supplicant.conf In the file Wifi The information is mainly in the following format , Each network information is represented by network start .key_mgmt=NONE The network does not need a password . When key_mgmt=WPA-PSK when , Will pass psk Field to identify the password information .

In the cell phones we've seen so far wpa_supplicant.conf There are no different networks in the file according to priority Sort by . And the networks that you use often priority Relatively high , It was put at the back of the file , Therefore, we should consider the network information according to priority Sort from big to small .

 String sortByPriority(String input){
String [] stringPerLine=input.split("\n");
ArrayList<NetworkPara> list=new ArrayList<MainActivity.NetworkPara>();
int start=0,end=0;
NetworkPara networkPara = null;
for (int i = 0; i < stringPerLine.length; i++) {
if (stringPerLine[i].contains("network={")) {
start=1;
end=0;
networkPara=new NetworkPara();
networkPara.paraString="";
}
if (start==1) {
if (networkPara!=null) {
networkPara.paraString=networkPara.paraString.concat(stringPerLine[i])+"\n";
}
if (stringPerLine[i].contains("priority")) {
String []prioSplit=stringPerLine[i].split("=");
networkPara.priority=Integer.parseInt(prioSplit[prioSplit.length-1]);
}
if (stringPerLine[i].contains("}")) {
start=0;
end=1;
}
}
if (end==1) {
list.add(networkPara);
}
}
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
return ((Comparable) ((NetworkPara) (o2)).priority)
.compareTo(((NetworkPara) (o1)).priority);
}
}); String result="";
for (int i = 0; i < list.size(); i++) {
result=result.concat(list.get(i).paraString);
}
return result;
}

2.3 Support search by string

The entry selection of string search is adopted in actionar Add a search button on the , Line by line matching based on the input string . When there are multiple matching results , The forward and backward buttons are displayed in the interface , To support the selection of before and after content .

2.3.1 Actionbar Show search button in

First, in the menu item Add search button when generating , Then master activity implements OnQueryTextListener And implement onQueryTextChange and onQueryTextSubmit Method [2].

 public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu); searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
searchView.setOnQueryTextListener(this);
return true;
}
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.zhigao.all_connect.MainActivity" > <item android:id="@+id/menu_search"
android:title="Search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"
/>
</menu>

2.3.2 String matching and result saving

After the user enters the characters to be searched, click search , perform onQueryTextSubmit function . use stringSplit[i].toLowerCase().contains(arg0.toLowerCase()) Do case insensitive matching . Use scrollTo Function scrollview The jump [5].

 public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
Log.v(TAG, "querysubmit"+arg0);
matchedLine.clear();
String []stringSplit=sortedResult.split("\n");
for (int i = 0; i < stringSplit.length; i++) {
//case insensitive match
if (stringSplit[i].toLowerCase().contains(arg0.toLowerCase())) {
matchedLine.add(i);
}
} if (matchedLine.size()==0) {
Toast.makeText(getApplicationContext(), "no match!", Toast.LENGTH_SHORT).show();
return false;
}else if (matchedLine.size()==1) { }
else {
forwardButton.setVisibility(View.VISIBLE);
backwardButton.setVisibility(View.VISIBLE);
}
scrollView.post(new Runnable() {
@Override
public void run() {
int y = textView.getLayout().getLineTop(matchedLine.get(0));
scrollView.scrollTo(0, y);
}
});
searchView.clearFocus();
return false;
}

2.3.3 When there are multiple strings to match, the result shows

be based on relativelayout Construct out button Floating in textview Effect on , When the user slides down scrollview when ,button Can always stay in the lower right position [6]. Users click the button to search forward or backward . Click on textview Then cancel the button .

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/ssidTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</ScrollView> <Button
android:id="@+id/backwardButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/backward"
/>
<Button
android:id="@+id/forwardButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/backwardButton"
android:layout_alignParentBottom="true"
android:background="@drawable/forward"
/>
</RelativeLayout>

2.4 Generate a signature apk The problems encountered in the process and the current solutions

2.4.1 Duplicate id @+id/image problem [7]

Generate signature apk function lint When checking , Prompt by Duplicate id @+id/image problem . Even if it's going to be android support library Update to 23.0.1 And then there's still . For now, we will abc_activity_chooser_view.xml Second of @+id/image It is amended as follows @+id/image2.

2.4.2 This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) problem

modify lint, Let's take this problem from error Judgment for warning.window->preferences -> Android Lint Preferences, Search for Instantiatable. Set it to warning.

2.4.3 "abc_action_bar_home_description_format" is not translated in "mk-rMK" problem

Because we don't consider supporting too many languages at present , and android This package may be updated later . So for the moment, we will consider lint Of missing chanslation Set to warning.

3、 ... and 、 Complete source code sharing

https://github.com/jue-jiang/wifiAssist

Four 、apk download

https://github.com/jue-jiang/wifiAssist/blob/master/wifiAssist.apk

5、 ... and 、 Reference material

[1] How Android phones view WIFI password _ Experience in baidu

[2]searchView.setOnQueryTextListener(this);

[3]java - Android Reading from an Input stream efficiently - Stack Overflow

[4]java - execute shell command from android - Stack Overflow

[5]java - How to scroll to a given line number, TextView inside ScrollView - Stack Overflow

[6]How to add a floating button on scrolling in android? - Stack Overflow

[7]Issue 73197 - android - abc_activity_chooser_view_include.xml uses android:id="@+id/image" twice - Android Open Source Project - Issue Tracker - Google Project Hosting

Android phone saved WiFi Password view assistant ( Open source ) More articles about

  1. Forget the password to visit the website frequently ? Show you how to view the saved password in the browser , How to simply view Chome Password saved by browser ?

    Use the scene : Colleagues or friends are out for business , Leave your seat with the computer unlocked . You can take advantage of this gap , see Ta stay Chrome Account password saved in browser View logic : When we want to see Chrome The password saved on the browser , Click to display , A dialog box will pop up ...

  2. Simple bypass Chrome Password view logic , View the password saved by the browser

    Simple bypass Chrome Password view logic , View the password saved by the browser   Use the scene : Colleagues or friends are out for business , Leave your seat with the computer unlocked . You can take advantage of this gap , see Ta stay Chrome Account password saved in browser View logic : When we want to check ...

  3. Experience in baidu :Win10 View stored WiFi Two ways to code

    Method 1 : Network and sharing center query Please refer to :Win10 see WIFI Password method Method 2 : Command prompt query 1. Right click the start button , choice “ Command prompt ( Administrators )” 2. Enter the following command ( The figure below ① Order number ): nets ...

  4. Chapter 18 BJROBOT The android mobile phone APP Map building 【ROS All open source Ackerman turns to intelligent networked driverless vehicle 】

    1. Lay the car flat on the floor , Use the virtual machine in the data , Open a terminal ssh  In the past, the main control terminal started roslaunch znjrobotbringup.launch 2. Open another terminal on the virtual machine side ,ssh  In the past, the main control terminal started ro ...

  5. How to view chrome Browser saved password

    This method is aimed at chrome The login password has been stored in . chrome The version is  66.0.3359.139( Official version ) (64 position ), I don't know when I will change this bug. Generally speaking , We land chrome The browser has ...

  6. windows View connected WIFI password

    find wifi Icon . Right click , Choose to open “ The Internet and internet Set up ”, Selection status . Select change adapter settings . Choose what you're connected to WIFI The Internet . Right click , Selection status . Select wireless properties . Choose safety . Check the display character .

  7. win10 Home view connected wifi password

    Click the wireless network icon in the lower right corner of the screen . Click Network Settings . complete .

  8. Android WiFi password ( View tools )

    Pure mobile terminal AIDE To write , Now share the source code & apk file . notes : Using this tool requires root jurisdiction . apk file : http://yunpan.cn/cHPLZ8zH5BQBV ( Extraction code :9cd2) ...

  9. windows git Clear the saved password

    Get into git Catalog Right click git-bash.exe Carry out orders : git config --system --unset credential.helper And then execute git clone http://... ...

Random recommendation

  1. oracle The table has been deleted by database misoperation , How to recover

    One : Recovery of watch For the table deleted by mistake , As long as it's not used PURGE Permanently delete option , So from flash back The hope of the district's recovery is great . The general steps are :1. from flash back Query the deleted table in select * from re ...

  2. Install Qt creator

    download qt for linux yum install dialog move download qt file(qt-opensource-linux-x64-5.6.0.run) fr ...

  3. JS_Ajax Basics

    One :Ajax ajax The full name is Asynchronous( asynchronous ) JavaScript and XML  Get... From the server without refreshing the page , A way of data interaction to submit data ; Two :Ajax Use steps to summarize //1 ...

  4. PL/SQL Developer Do not install the client connection remote oracle database ( turn )

    1. Download agile client InstantClient(40M about , Choose your own download , My is instantclient-basic-win32-11.2.0.1.0.zip ):http://www.orac ...

  5. Quartz Dynamically changing mission time

    be based on quartz-2.2 Dynamic task scheduling of Quartz Is a completely by java Write the open source job scheduling framework . Scheduler Quartz The core of the framework is the scheduler . The scheduler is responsible for managing Quartz Application runtime environment . The scheduler is not made on its own ...

  6. js Verify the URL URL Format

    /^((ht|f)tps?):\/\/([\w\-]+(\.[\w\-]+)*\/)*[\w\-]+(\.[\w\-]+)*\/?(\?([\w\-\.,@?^=%&:\/~\+#]*)+)? ...

  7. centOS No problem connecting , Use SecureCRT You can't connect

    reason : take NAT Change the mode to a custom mode :

  8. Seckill system -DAO

    DAO(Data Access Object) Data access object First, you need to create a second kill inventory table and a second kill success list , As shown below : CREATE DATABASE seckill; use seckill; CREAT ...

  9. C# 3.0 / C# 3.5 Extension method

    summary The extension method is a special static method , It can be called like an instance method on an extended type , Can be extended to existing types “ add to ” Method , Instead of creating a new derived type . Recompile or otherwise modify the original type . The definition and implementation of extension method : public s ...

  10. 2016 Blog guide summary &amp;amp; Personal perception

    At the beginning of this article .2017 It's already in front of us . It's expected that when I finish ,2017 It's already here . The second edition is in 2017 year 1 month 1 Early Wednesday morning 11 spot . About 2016 The feeling . I wanted to write in early December , I thought it was too early , But my mind is like a spring . And it was just ...