@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.btn_getID);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
getCurrentProcessName(getApplicationContext());
}
});
}
void getCurrentProcessName(Context context) {
Integer pid = android.os.Process.myPid();
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : activityManager
.getRunningAppProcesses()) {
Log.i("ProcessId:", appProcess.processName);
}
Log.i("MyProcess:", pid.toString());
}
Android 获取当前进程
最新推荐文章于 2024-08-15 04:06:30 发布