我需要知道是否有接收方可以检测用户通过我自己的应用程序单击或启动了哪个应用程序
i think you can use logcat
and analyze it's output.
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.
UPDATED: find the which application is launched, by Tracking the Logcat . Just Track on ActivityManager tag with info -I log.
From adb shell Command is,
adb logcat ActivityManager:I *:S
From your application code,
logcat ActivityManager:I *:S
And in Logcat you can find a line something like,
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":
Just add permission in your Application's manifest file,
android.permission.READ_LOGS
自android 4.1起不推荐使用,应用只能使用android.permission.READ_LOGS访问其自己的日志
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.