Commits

vios@ylab  committed a9d2502

try get my proccess id

  • Participants
  • Parent commits e05e758

Comments (0)

Files changed (1)

File src/foo/sample/GetIP/GetIP.java

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.List;
 
 import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningAppProcessInfo;
+import android.app.ActivityManager.RunningTaskInfo;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 	EditText etNum = null;
 	BufferedReader br = null;
     String outStr = "";
+    private int pid = -1;
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         findViewById(R.id.button1).setOnClickListener(this);
         etNum = (EditText)findViewById(R.id.editText1);
     }
+    @Override
+    public void onStart()
+    {
+    	super.onStart();
+    	pid = -1;
+    	String myPackageName = getApplicationContext().getPackageName();
+    	Log.d("debug","myPackage name is:"+myPackageName);
+    	ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
+    	List<RunningAppProcessInfo> runningApp = am.getRunningAppProcesses();
+    	for(RunningAppProcessInfo app:runningApp)
+    	{
+    		if(app.processName.equals(myPackageName))
+    		{
+    			pid = app.pid;
+    		}
+    	}
+    	
+    	
+    	
+    }
 	@Override
 	public void onClick(View arg0) {
 		// TODO Auto-generated method stub
 				Log.d("debug",proc.getOutputStream().toString());
 			}
 			*/
+			getApplicationInfo().
+			g
             try {
             	int i = Integer.valueOf(etNum.getText().toString());
 				Log.d("debug","try to get proccess" + i);