[英]How to detect which application is clicked/launched by the user through my application in android
我需要知道是否有接收方可以检测用户通过我自己的应用程序单击或启动了哪个应用程序
i think you can use logcat
and analyze it's output. 我认为您可以使用
logcat
并分析其输出。
in all similar programs i found this permission : 在所有类似的程序中,我都获得了此许可:
android.permission.READ_LOGS
that mean all of them use it. 这意味着所有人都使用它。 but it seems the program starts and after that our program (app protector) will start and bring front.
但似乎程序启动了,之后我们的程序(应用保护程序)就会启动并取得领先。
use below code : 使用以下代码:
try
{
Process mLogcatProc = null;
BufferedReader reader = null;
mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
String line;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null)
{
log.append(line);
log.append(separator);
}
String w = log.toString();
Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
and do not forget it s permission on android manifest. 并且不要忘记它对android manifest的许可。
UPDATED: find the which application is launched, by Tracking the Logcat . 更新:通过跟踪Logcat查找启动了哪个应用程序。 Just Track on ActivityManager tag with info -I log.
只需跟踪带有信息-I日志的ActivityManager标签即可。
From adb shell Command is, 从adb shell命令开始,
adb logcat ActivityManager:I *:S
From your application code, 根据您的应用程序代码,
logcat ActivityManager:I *:S
And in Logcat you can find a line something like, 在Logcat中,您可以找到类似以下内容的行:
I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
When any application will launched. 什么时候将启动任何应用程序。
It is logcat output that shows that the message relates to priority level "I" and tag "ActivityManager": logcat输出显示该消息与优先级“ I”和标签“ ActivityManager”有关:
Just add permission in your Application's manifest file, 只需在应用程序的清单文件中添加权限,
android.permission.READ_LOGS android.permission.READ_LOGS
自android 4.1起不推荐使用,应用只能使用android.permission.READ_LOGS访问其自己的日志
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.