Anonymous avatar Anonymous committed 924bc5d

LogをListViewに登録しようとしたがなぜかTCPの結果しか取得できなくなった

Comments (0)

Files changed (3)

res/layout/main.xml

     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
+    <ListView
+    android:id="@+id/listview"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:fastScrollEnabled="true"
+    ></ListView>
 </LinearLayout>

src/foo/sample/GetIP/ConnectionData.java

 package foo.sample.GetIP;
 
-import android.content.pm.PackageManager;
+import java.util.List;
+
 import android.text.format.Formatter;
 import android.util.Log;
 
 		Log.d("debug","LocalIP:"+Formatter.formatIpAddress(localIP)+":"+localPort);
 		Log.d("debug","remoteIP:"+Formatter.formatIpAddress(remoteIP)+":"+remotePort);
 	}
+	public void debugInfo(List<String> output)
+	{
+		output.add("start:debugInfo()");
+		output.add("UID:"+uid);
+		output.add("ConnectionType:"+CONNECTION_TYPE[connectionType]);
+		output.add("stat:"+getState());
+		output.add("LocalIP:"+Formatter.formatIpAddress(localIP)+":"+localPort);
+		output.add("remoteIP:"+Formatter.formatIpAddress(remoteIP)+":"+remotePort);
+	}
 
 }

src/foo/sample/GetIP/GetIP.java

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Bundle;
 import android.util.Log;
+import android.widget.ArrayAdapter;
 import android.widget.EditText;
+import android.widget.ListAdapter;
+import android.widget.ListView;
 
 public class GetIP extends Activity{
     /** Called when the activity is first created. */
+	ListView lv;
 	Process proc = null;
 	EditText etNum = null;
 	BufferedReader br = null;
     public void onStart()
     {
     	super.onStart();
+    	List<String> outputList = new ArrayList<String>();
     	myPid = getMyPid();
     	if(myPid == -1)
     	{
     	{
     		Log.d("debug","Succsess to get myPid:" + myPid);
     	}
-    	showNetInfo();
+    	showNetInfo(outputList);
+    	Log.d("debug","prepaering ListAdapter and ListView,the outputList:" + outputList);
+    	ListAdapter la = (ListAdapter) new  ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_expandable_list_item_1,outputList);
+    	lv = (ListView)findViewById(R.id.listview);
+    	lv.setAdapter(la);
     }
     private int getMyPid()
     {
     	}
     	return ret;
     }
-    private void getTCP6Info()
+    private void getTCP6Info(List<String> output)
     {
     	PackageManager pm = this.getPackageManager();
     	ConnectionData connectionData = new ConnectionData();
             		  	}
             		  	String packageName = pm.getNameForUid(connectionData.uid);
             		  	Log.d("debug","uid=" + connectionData.uid + " packagename:" + packageName);
+            		  	output.add("uid=" + connectionData.uid + " packagename:" + packageName);
             		  	try {
 							Log.d("debug","App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
+							output.add("App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
 						} catch (NameNotFoundException e) {
 							e.printStackTrace();
 						}
-            		  	connectionData.debugInfo();
+            		  	//connectionData.debugInfo();
+            		  	connectionData.debugInfo(output);
             		  }
             	  else
             	  {
                }
 			}
     }
-    public void getTCPInfo()
+    public void getTCPInfo(List<String> output)
 
     {
     	PackageManager pm = this.getPackageManager();
             		  	}
             		  	String packageName = pm.getNameForUid(connectionData.uid);
             		  	Log.d("debug","uid=" + connectionData.uid + " packagename:" + packageName);
+            		  	output.add("uid=" + connectionData.uid + " packagename:" + packageName);
             		  	try {
 							Log.d("debug","App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
+							output.add("App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
 						} catch (NameNotFoundException e) {
 							e.printStackTrace();
 						}
-            		  	connectionData.debugInfo();
+            		  	//connectionData.debugInfo()
+            		  	connectionData.debugInfo(output);
             		  }
             	  else
             	  {
                }
 			}
     }
-    public void getUDPInfo()
+    public void getUDPInfo(List<String> output)
     {
     	PackageManager pm = this.getPackageManager();
     	ConnectionData connectionData = new ConnectionData();
             		  	}
             		  	String packageName = pm.getNameForUid(connectionData.uid);
             		  	Log.d("debug","uid=" + connectionData.uid + " packagename:" + packageName);
+            		  	output.add("uid=" + connectionData.uid + " packagename:" + packageName);
             		  	try {
 							Log.d("debug","App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
+							output.add("App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
 						} catch (NameNotFoundException e) {
 							e.printStackTrace();
 						}
-            		  	connectionData.debugInfo();
+            		  	//connectionData.debugInfo();
+            		  	connectionData.debugInfo(output);
             		  }
             	  else
             	  {
                }
 			}
     }
-    void getUDP6Info()
+    void getUDP6Info(List<String> output)
     {
     	PackageManager pm = this.getPackageManager();
     	ConnectionData connectionData = new ConnectionData();
             		  	}
             		  	String packageName = pm.getNameForUid(connectionData.uid);
             		  	Log.d("debug","uid=" + connectionData.uid + " packagename:" + packageName);
+            		  	output.add("uid=" + connectionData.uid + " packagename:" + packageName);
             		  	try {
-							Log.d("debug","App\' s path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
+							Log.d("debug","App's path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
+							output.add("App's path:"+pm.getApplicationInfo(packageName, 0).publicSourceDir);
 						} catch (NameNotFoundException e) {
 							e.printStackTrace();
 						}
-            		  	connectionData.debugInfo();
+            		  	//connectionData.debugInfo();
+            		  	connectionData.debugInfo(output);
             		  }
             	  else
             	  {
     		ret *= 16;
     		ret += Character.digit(num.charAt(i),16);
     	}
-    	
     	return ret;
     }
-	public void showNetInfo() {
-		getUDP6Info();
-		getTCP6Info();
-		getUDPInfo();
-		getTCPInfo();
+	public void showNetInfo(List<String> output) {
+		getUDP6Info(output);
+		getUDP6Info(output);
+		getUDP6Info(output);
+		getTCPInfo(output);
 	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.