![](/img/trans.png)
[英]How to terminate an application which is launched from my current application in android?
[英]How to detect which application is clicked/launched by the user through my application in android
我需要知道是否有接收方可以检测用户通过我自己的应用程序单击或启动了哪个应用程序
我认为您可以使用logcat
并分析其输出。
在所有类似的程序中,我都获得了此许可:
android.permission.READ_LOGS
这意味着所有人都使用它。 但似乎程序启动了,之后我们的程序(应用保护程序)就会启动并取得领先。
使用以下代码:
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();
}
并且不要忘记它对android manifest的许可。
更新:通过跟踪Logcat查找启动了哪个应用程序。 只需跟踪带有信息-I日志的ActivityManager标签即可。
从adb shell命令开始,
adb logcat ActivityManager:I *:S
根据您的应用程序代码,
logcat ActivityManager:I *:S
在Logcat中,您可以找到类似以下内容的行:
I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
什么时候将启动任何应用程序。
logcat输出显示该消息与优先级“ I”和标签“ ActivityManager”有关:
只需在应用程序的清单文件中添加权限,
android.permission.READ_LOGS
自android 4.1起不推荐使用,应用只能使用android.permission.READ_LOGS访问其自己的日志
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.