[Android] Add logcat dumping option

Edward Wang git at videolan.org
Thu Jan 30 15:26:50 CET 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Jan 30 09:05:55 2014 -0500| [dcad48233a38878fa968dd4c18790e9ca8a04822] | committer: Edward Wang

Add logcat dumping option

Since Android 4.2 or so apps like Term.apk no longer work as each app unless rooted can only access its own logcat.

Hence, this commit provides an easier way to dump the logcat log than enabling developer options and connecting to a computer.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=dcad48233a38878fa968dd4c18790e9ca8a04822
---

 vlc-android/res/values/strings.xml                 |    3 ++
 vlc-android/res/xml/preferences.xml                |    5 +++
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   36 ++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 9a62910..1067155 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -237,6 +237,9 @@
     <string name="set_locale_detail">Leave blank to reset</string>
     <string name="set_locale_popup">Quit and reset VLC for changes to take effect.</string>
     <string name="quit">Quit and restart application</string>
+    <string name="dump_logcat">Dump logcat log</string>
+    <string name="dump_logcat_success">Logcat successfully dumped to %1$s!</string>
+    <string name="dump_logcat_failure">Failed to dump logcat.</string>
 
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index bd7cb5f..b3df7eb 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -126,6 +126,11 @@
                 android:enabled="true"
                 android:key="quit_app"
                 android:title="@string/quit" />
+
+            <Preference
+                android:enabled="true"
+                android:key="dump_logcat"
+                android:title="@string/dump_logcat" />
         </PreferenceScreen>
     </PreferenceCategory>
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 47d35ff..e6e8513 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -27,6 +27,7 @@ import org.videolan.vlc.BitmapCache;
 import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioUtil;
 
 import android.app.AlertDialog;
@@ -36,6 +37,7 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.os.Bundle;
+import android.os.Environment;
 import android.preference.CheckBoxPreference;
 import android.preference.EditTextPreference;
 import android.preference.ListPreference;
@@ -45,6 +47,7 @@ import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceScreen;
+import android.text.format.DateFormat;
 import android.widget.Toast;
 
 @SuppressWarnings("deprecation")
@@ -174,6 +177,39 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                         return true;
                     }
                 });
+
+        Preference dumpLogcatLog = findPreference("dump_logcat");
+        dumpLogcatLog.setOnPreferenceClickListener(
+                new OnPreferenceClickListener() {
+                    @Override
+                    public boolean onPreferenceClick(Preference preference) {
+                        if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+                            Toast.makeText(PreferencesActivity.this,
+                                    R.string.dump_logcat_failure,
+                                    Toast.LENGTH_LONG).show();
+                            return true;
+                        }
+
+                        CharSequence timestamp = DateFormat.format(
+                                "yyyyMMdd_kkmmss", System.currentTimeMillis());
+                        String filename = Environment.getExternalStorageDirectory().getPath() + "/vlc_logcat_" + timestamp + ".log";
+                        try {
+                            Util.writeLogcat(filename);
+                            Toast.makeText(
+                                    PreferencesActivity.this,
+                                    String.format(
+                                            VLCApplication.getAppResources().getString(R.string.dump_logcat_success),
+                                            filename), Toast.LENGTH_LONG)
+                                    .show();
+                        } catch (Exception e) {
+                            Toast.makeText(PreferencesActivity.this,
+                                    R.string.dump_logcat_failure,
+                                    Toast.LENGTH_LONG).show();
+                        }
+                        return true;
+                    }
+                });
+
         // Audio output
         ListPreference aoutPref = (ListPreference) findPreference("aout");
         int aoutEntriesId = Util.isGingerbreadOrLater() ? R.array.aouts : R.array.aouts_froyo;



More information about the Android mailing list