![](/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.