gpt4 book ai didi

android - 如何查看Android默认浏览器是否已经打开?

转载 作者:行者123 更新时间:2023-11-29 22:01:52 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate: How can I check if an app running on Android?

我想知道是否有办法检查Android默认浏览器(Android OS中的浏览器)是否已打开。假设它打开了,我想显示一个 toast 。我如何以编程方式执行此操作?

这是我在扩展服务类的类中使用的代码,该类监听日志并检查是否已打开 Android 默认浏览器。如果是,那么它将在 LogCat 中打印日志表示已打开 Android 默认浏览器。

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();
Log.d("LogService", "The log is: " + w);

if (w.contains("Starting activity: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity }")) {
Log.d("LogService", "The browser has been opened");
}

}
catch (Exception e) {
Log.d("LogService", "The stacktrace is: " + e.getMessage());
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com