Android app using android.permission.READ_LOGS - i

2020-07-10 03:06发布

问题:

I have an app that is available from the Android Market. Some users have asked for a way of debugging when things don't work out as expected. I have been looking into adding a menu item that will display the output of


    Process mLogcatProc = null;
    BufferedReader reader = null;
    mLogcatProc = Runtime.getRuntime().exec(
        new String[] {"logcat", "-d", "AndroidRuntime:E BDtN:V *:S" });
    reader = new BufferedReader(new InputStreamReader (mLogcatProc.getInputStream()));
    String line;
    ArrayList listOfLogLines = new ArrayList();
    while ((line = reader.readLine()) != null)
    {
        listOfLogLines.add(line);
    }

Basically I am extracting the parts of the Log.* lines that my app has been writing and the errors that the AndroidRuntime has been throwing.

I have a working prototype that will display to the user the contents of the part of the log that I have extracted in a ListView.

I will have to add android.permission.READ_LOGS to the AndroidManifest.xml file in order for my app to have read access to the log, and this of course will be information that the user will be prompted with before installing. And the question is if this is considered impolite, dangerous or otherwise out of the ordinary. Will it keep users from installing?

回答1:

I wouldn't install an app that did this. If all you want is your own logs, your app can keep its own private log buffer that it writes into along with the system log.

You may not even need to do this though: http://android-developers.blogspot.com/2010/05/google-feedback-for-android.html



回答2:

Don't make your live difficult and risk problems with your user! java.util.logging is available on android as well (and even forwarded to android.util.Log) and a java.util.logging.Handler will do everything you want.