zoukankan      html  css  js  c++  java
  • Android -- 查看手机中所有进程

    布局                                                                                   

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/updateBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Update ProcessInfos" />
    
        <TextView
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textStyle="bold" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp" 
                android:padding="5dp"/>
        </ScrollView>
    
    </LinearLayout>

    Code                                                                                  

    public class HelloProcessActivity extends Activity
    {
        private TextView mTextView = null;
        private TextView mTime = null;
        private Button mButton = null;
        private String mText = "";
    
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_hello_process);
    
            mTextView = (TextView) findViewById(R.id.text);
            mTime = (TextView) findViewById(R.id.time);
            mButton = (Button) findViewById(R.id.updateBtn);
    
            mButton.setOnClickListener(new View.OnClickListener()
            {
    
                @Override
                public void onClick(View v)
                {
                    updateProcessInfo();
                }
            });
    
        }
    
        private void updateProcessInfo()
        {
            mText = "";
            mTextView.setText(mText);
    
            // 获取ActivityManager
            ActivityManager activityManager = (ActivityManager) this
                    .getSystemService(Context.ACTIVITY_SERVICE);
    
            // 更新时间
            updateTimeInfo();
    
            // 获取进程信息***************************************************
            List<RunningAppProcessInfo> infos = activityManager
                    .getRunningAppProcesses();
    
            for (RunningAppProcessInfo info : infos)
            {
                String name = info.processName;
    
                mText = mTextView.getText().toString();
                mText += name + "
    
    ";
                mTextView.setText(mText);
    
            }
    
        }
    
        private void updateTimeInfo()
        {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
            String time = df.format(new Date());
            System.out.println(time);// new Date()为获取当前系统时间
    
            mTime.setText(time);
    
        }
    
    }

    我是天王盖地虎的分割线                                                             

    参考:http://www.cnblogs.com/mengdd/p/3213378.html

  • 相关阅读:
    新浪微博 js 解密
    新浪微博、qq rsa密码加密c#实现
    C#版本的discuz authcode函数
    搬地方了,在github弄了个新博客
    python 发送邮件
    通用网页广告监测,ADBlock plus算法的C#实现。
    58同城登录 c#,非直接操作js
    python模块之smtplib: 用python发送SSL/TLS安全邮件
    Python少打字小技巧
    python模块之poplib: 用pop3收取邮件
  • 原文地址:https://www.cnblogs.com/yydcdut/p/3952663.html
Copyright © 2011-2022 走看看