Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if the Android default browser has been opened?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong> <a href="https://stackoverflow.com/questions/4212992">How can I check if an app running on Android?</a></p> </blockquote> <p>I would like to know if there is a way to check if the Android default browser (browser in Android OS) has been opened. Suppose it's opened, I would like a toast to be displayed. How can I do this programmatically?</p> <p>This is the code that I used in the class that extends the Service class which listens to the logs and checks if the Android default browser has been opened. If it is then it prints a log in the <a href="https://sites.google.com/site/androidhowto/how-to-1/save-logcat-to-a-text-file" rel="nofollow noreferrer">LogCat</a> stating that the Android default browser has been opened.</p> <pre><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(); 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()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload