Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Get the string of all log messages as posted in the answer you mentioned. Then, simply search the string using regular expressions.</p> <p>For example, </p> <pre><code>String result = //... get the logs ... if(result.contains("trigger text i am looking for")){ myObject.raiseEvent(); } </code></pre> <p>EDIT</p> <p>If you are trying to do a constant monitoring of the logcat, this will be much more difficult. For one, the process might get shut down without warning. So you need a way to keep it running, or to constantly check that it is running.</p> <p>Secondly, the solution you linked to would not work in this case, as that waits until stopLogging is called, then returns the entire log for the recorded interval.</p> <p>Also, you'll have to modify that code so that it has a list of trigger words and their associated callback functions to run.</p> <pre><code>while ((line = reader.readLine()) != null){ for(int i =0; i &lt; triggerList.size(); i++){ TriggerPhrase trigger = triggerList.get(i); if(line.contains(trigger.phrase)) { trigger.onTriggerPhrase(line); } } } </code></pre> <p>where TriggerPhrase is a simple class that has a String phrase member variable and an object that implements a callback function.</p> <pre><code>public static class TriggerPhrase implements TriggerListener{ String phrase; TriggerListener callback; } public interface TriggerListener{ public void onTriggerPhrase(); } </code></pre> <p>Then before you start listening the logs, you populate the triggerPhrases <code>List</code> in the LogCat listener.</p> <pre><code>TriggerPhrase monkeyPhrase = new TriggerPhrase(); monkeyPhrase.phrase = "monkeys"; monkeyPhrase.callback = new TriggerListener(){ public void onTriggerPhrase(){ notifyUser("found the phrase `monkeys` in the logcat"); } }; triggerPhrases.add(monkeyPhrase); //etc. </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.
    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