duanqian1888 2017-12-26 12:24
浏览 339

Android:如何获取前台应用程序的进程ID

First of all, please note that this question is not same as all the "android foreground app" questions I found on SO, please read on :-)

I am trying to write an android app for my own use, using golang, without using android-sdk or ndk (this is the KEY point). It is pretty simple, just use golang to write a http service, compile it for arm cpu and voila my app is running and can be access by simply visit http://localhost.

For the purpose of my app, I need to know the currently running foreground application, to define it precisely:

1) foreground application is the application that occupies the screen, or has an "activity" what-so-ever (forgive me I am not an android developer).

2) anything that that is depended by the foreground application (e.g. services) is NOT what I am interested in.

3) if the phone is LOCKED/screen turned off, I want the solution to tell me there is NO foreground app.

And since I do not use anything android, just treat the phone as a linux machine, I want the solution to use native linux ways, e.g. by inspect /proc, or by calling any installed android command line tool (including sending messages via these command line tools), but NOT using any SDK/NDK way so that I have to use java or incorporate these thing into my app.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥30 求解达问题(有红包)