Example usage for android.content SharedPreferences getAll

List of usage examples for android.content SharedPreferences getAll

Introduction

In this page you can find the example usage for android.content SharedPreferences getAll.

Prototype

Map<String, ?> getAll();

Source Link

Document

Retrieve all values from the preferences.

Usage

From source file:com.murrayc.galaxyzoo.app.LoginUtils.java

static void copyPrefsToAccount(final Context context, final AccountManager accountManager,
        final Account account) {
    //Copy the preferences into the account.
    //See also SettingsFragment.onSharedPreferenceChanged()
    final SharedPreferences prefs = Utils.getPreferences(context);
    final Map<String, ?> keys = prefs.getAll();
    for (final Map.Entry<String, ?> entry : keys.entrySet()) {
        final Object value = entry.getValue();
        if (value instanceof String) {
            copyPrefToAccount(accountManager, account, entry.getKey(), (String) value);
        } else if (value instanceof Integer) {
            copyPrefToAccount(accountManager, account, entry.getKey(), Integer.toString((Integer) value));
        } else if (value instanceof Boolean) {
            copyPrefToAccount(accountManager, account, entry.getKey(), Boolean.toString((Boolean) value));
        }//from  w w  w  .  j av  a  2 s .  c o  m
    }
}

From source file:com.unovo.frame.utils.SharedPreferencesHelper.java

/**
 * {@link SharedPreferences}?Bean//from  w  w  w .ja  v a  2  s .  c o  m
 * SharedPreferences??NULL
 *  {@link #load(Context, Class)} 
 * ?????{@link SharedPreferences}
 *
 * @param context Context
 * @param clx Bean'class
 * @param <T> Any Bean
 * @return ?Bean
 */
@SuppressWarnings("unchecked")
public static <T> T loadFormSource(Context context, Class<T> clx) {
    SharedPreferences sp = getSharedPreferences(context, clx);

    // Use reflection to force refresh data
    try {
        Reflector.with(sp).call("startReloadIfChangedUnexpectedly");
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Get all existing key
    Set<String> existKeys = sp.getAll().keySet();
    if (existKeys.size() == 0)
        return null;
    return (T) buildTargetFromSource(clx, null, "", existKeys, sp);
}

From source file:com.master.metehan.filtereagle.Receiver.java

public static void upgrade(boolean initialized, Context context) {
    synchronized (context.getApplicationContext()) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        int oldVersion = prefs.getInt("version", -1);
        int newVersion = Util.getSelfVersionCode(context);
        if (oldVersion == newVersion)
            return;
        Log.i(TAG, "Upgrading from version " + oldVersion + " to " + newVersion);

        SharedPreferences.Editor editor = prefs.edit();

        if (initialized) {
            if (oldVersion < 38) {
                Log.i(TAG, "Converting screen wifi/mobile");
                editor.putBoolean("screen_wifi", prefs.getBoolean("unused", false));
                editor.putBoolean("screen_other", prefs.getBoolean("unused", false));
                editor.remove("unused");

                SharedPreferences unused = context.getSharedPreferences("unused", Context.MODE_PRIVATE);
                SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi",
                        Context.MODE_PRIVATE);
                SharedPreferences screen_other = context.getSharedPreferences("screen_other",
                        Context.MODE_PRIVATE);

                Map<String, ?> punused = unused.getAll();
                SharedPreferences.Editor edit_screen_wifi = screen_wifi.edit();
                SharedPreferences.Editor edit_screen_other = screen_other.edit();
                for (String key : punused.keySet()) {
                    edit_screen_wifi.putBoolean(key, (Boolean) punused.get(key));
                    edit_screen_other.putBoolean(key, (Boolean) punused.get(key));
                }//from   w  ww.j a  v  a 2  s .  c o  m
                edit_screen_wifi.apply();
                edit_screen_other.apply();
            }
        } else {
            Log.i(TAG, "Initializing sdk=" + Build.VERSION.SDK_INT);
            editor.putBoolean("whitelist_wifi", false);
            editor.putBoolean("whitelist_other", false);
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
                editor.putBoolean("filter", true); // Optional
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            editor.putBoolean("filter", true); // Mandatory

        editor.putInt("version", newVersion);
        editor.apply();
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void upgrade(boolean initialized, Context context) {
    synchronized (context.getApplicationContext()) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        int oldVersion = prefs.getInt("version", -1);
        int newVersion = Util.getSelfVersionCode(context);
        if (oldVersion == newVersion)
            return;
        Log.i(TAG, "Upgrading from version " + oldVersion + " to " + newVersion);

        SharedPreferences.Editor editor = prefs.edit();

        if (initialized) {
            if (oldVersion < 38) {
                Log.i(TAG, "Converting screen wifi/mobile");
                editor.putBoolean("screen_wifi", prefs.getBoolean("unused", false));
                editor.putBoolean("screen_other", prefs.getBoolean("unused", false));
                editor.remove("unused");

                SharedPreferences unused = context.getSharedPreferences("unused", Context.MODE_PRIVATE);
                SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi",
                        Context.MODE_PRIVATE);
                SharedPreferences screen_other = context.getSharedPreferences("screen_other",
                        Context.MODE_PRIVATE);

                Map<String, ?> punused = unused.getAll();
                SharedPreferences.Editor edit_screen_wifi = screen_wifi.edit();
                SharedPreferences.Editor edit_screen_other = screen_other.edit();
                for (String key : punused.keySet()) {
                    edit_screen_wifi.putBoolean(key, (Boolean) punused.get(key));
                    edit_screen_other.putBoolean(key, (Boolean) punused.get(key));
                }//  ww w  . j  a va  2 s  .  co m
                edit_screen_wifi.apply();
                edit_screen_other.apply();
            }
        } else {
            Log.i(TAG, "Initializing sdk=" + Build.VERSION.SDK_INT);
            editor.putBoolean("whitelist_wifi", false);
            editor.putBoolean("whitelist_other", false);
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
                editor.putBoolean("filter", true); // Optional
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            editor.putBoolean("filter", true); // Mandatory

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            editor.remove("show_top");
            if ("data".equals(prefs.getString("sort", "name")))
                editor.remove("sort");
        }

        if (Util.isPlayStoreInstall(context)) {
            editor.remove("update_check");
            editor.remove("use_hosts");
            editor.remove("hosts_url");
        }

        if (!Util.isDebuggable(context))
            editor.remove("loglevel");

        editor.putInt("version", newVersion);
        editor.apply();
    }
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void sendLogcat(final Uri uri, final Context context) {
    AsyncTask task = new AsyncTask<Object, Object, Intent>() {
        @Override/*from   www  .  jav  a2  s  .  c  o  m*/
        protected Intent doInBackground(Object... objects) {
            StringBuilder sb = new StringBuilder();
            sb.append(context.getString(R.string.msg_issue));
            sb.append("\r\n\r\n\r\n\r\n");

            // Get version info
            String version = getSelfVersionName(context);
            sb.append(String.format("NetGuard: %s/%d\r\n", version, getSelfVersionCode(context)));
            sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
            sb.append("\r\n");

            // Get device info
            sb.append(String.format("Brand: %s\r\n", Build.BRAND));
            sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
            sb.append(String.format("Model: %s\r\n", Build.MODEL));
            sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
            sb.append(String.format("Device: %s\r\n", Build.DEVICE));
            sb.append(String.format("Host: %s\r\n", Build.HOST));
            sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
            sb.append(String.format("Id: %s\r\n", Build.ID));
            sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context)));

            String abi;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
                abi = Build.CPU_ABI;
            else
                abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?");
            sb.append(String.format("ABI: %s\r\n", abi));

            sb.append("\r\n");

            sb.append(String.format("VPN dialogs: %B\r\n",
                    isPackageInstalled("com.android.vpndialogs", context)));
            try {
                sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null));
            } catch (Throwable ex) {
                sb.append("Prepared: ").append((ex.toString())).append("\r\n")
                        .append(Log.getStackTraceString(ex));
            }
            sb.append(String.format("Permission: %B\r\n", hasPhoneStatePermission(context)));
            sb.append("\r\n");

            sb.append(getGeneralInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getNetworkInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getSubscriptionInfo(context));
            sb.append("\r\n\r\n");

            // Get settings
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            Map<String, ?> all = prefs.getAll();
            for (String key : all.keySet())
                sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n");
            sb.append("\r\n");

            // Write logcat
            OutputStream out = null;
            try {
                Log.i(TAG, "Writing logcat URI=" + uri);
                out = context.getContentResolver().openOutputStream(uri);
                out.write(getLogcat().toString().getBytes());
                out.write(getTrafficLog(context).toString().getBytes());
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n");
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ignored) {
                    }
            }

            // Build intent
            Intent sendEmail = new Intent(Intent.ACTION_SEND);
            sendEmail.setType("message/rfc822");
            sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "marcel+netguard@faircode.eu" });
            sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat");
            sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            return sendEmail;
        }

        @Override
        protected void onPostExecute(Intent sendEmail) {
            if (sendEmail != null)
                try {
                    context.startActivity(sendEmail);
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }
    };
    task.execute();
}

From source file:eu.faircode.adblocker.Util.java

public static void sendLogcat(final Uri uri, final Context context) {
    AsyncTask task = new AsyncTask<Object, Object, Intent>() {
        @Override/*from w  ww  .jav  a 2  s  .com*/
        protected Intent doInBackground(Object... objects) {
            // Get device info
            StringBuilder sb = new StringBuilder();
            String version = getSelfVersionName(context);
            sb.append(String.format("adblocker: %s/%d\r\n", version, getSelfVersionCode(context)));
            sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
            sb.append("\r\n");

            sb.append(String.format("Brand: %s\r\n", Build.BRAND));
            sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
            sb.append(String.format("Model: %s\r\n", Build.MODEL));
            sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
            sb.append(String.format("Device: %s\r\n", Build.DEVICE));
            sb.append(String.format("Host: %s\r\n", Build.HOST));
            sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
            sb.append(String.format("Id: %s\r\n", Build.ID));
            sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context)));

            String abi;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
                abi = Build.CPU_ABI;
            else
                abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?");
            sb.append(String.format("ABI: %s\r\n", abi));

            sb.append("\r\n");

            sb.append(String.format("VPN dialogs: %B\r\n",
                    isPackageInstalled("com.android.vpndialogs", context)));
            try {
                sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null));
            } catch (Throwable ex) {
                sb.append("Prepared: ").append((ex.toString())).append("\r\n")
                        .append(Log.getStackTraceString(ex));
            }
            sb.append(String.format("Permission: %B\r\n", hasPhoneStatePermission(context)));
            sb.append("\r\n");

            sb.append(getGeneralInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getNetworkInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getSubscriptionInfo(context));
            sb.append("\r\n\r\n");

            // Get settings
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            Map<String, ?> all = prefs.getAll();
            for (String key : all.keySet())
                sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n");
            sb.append("\r\n");

            // Finalize message
            sb.append("Please describe your problem:\r\n");
            sb.append("\r\n");

            // Write logcat
            OutputStream out = null;
            try {
                Log.i(TAG, "Writing logcat URI=" + uri);
                out = context.getContentResolver().openOutputStream(uri);
                out.write(getLogcat().toString().getBytes());
                out.write(getTrafficLog(context).toString().getBytes());
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n");
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ignored) {
                    }
            }

            // Build intent
            Intent sendEmail = new Intent(Intent.ACTION_SEND);
            sendEmail.setType("message/rfc822");
            sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "marcel+adblocker@faircode.eu" });
            sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat");
            sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            return sendEmail;
        }

        @Override
        protected void onPostExecute(Intent sendEmail) {
            if (sendEmail != null)
                try {
                    context.startActivity(sendEmail);
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }
    };
    task.execute();
}

From source file:com.master.metehan.filtereagle.Util.java

public static void sendLogcat(final Uri uri, final Context context) {
    AsyncTask task = new AsyncTask<Object, Object, Intent>() {
        @Override/*from  w  ww  . j av  a2 s . c  om*/
        protected Intent doInBackground(Object... objects) {
            StringBuilder sb = new StringBuilder();
            sb.append(context.getString(R.string.msg_issue));
            sb.append("\r\n\r\n\r\n\r\n");

            // Get version info
            String version = getSelfVersionName(context);
            sb.append(String.format("FilterEagle: %s/%d\r\n", version, getSelfVersionCode(context)));
            sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
            sb.append("\r\n");

            // Get device info
            sb.append(String.format("Brand: %s\r\n", Build.BRAND));
            sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
            sb.append(String.format("Model: %s\r\n", Build.MODEL));
            sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
            sb.append(String.format("Device: %s\r\n", Build.DEVICE));
            sb.append(String.format("Host: %s\r\n", Build.HOST));
            sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
            sb.append(String.format("Id: %s\r\n", Build.ID));
            sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context)));

            String abi;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
                abi = Build.CPU_ABI;
            else
                abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?");
            sb.append(String.format("ABI: %s\r\n", abi));

            sb.append("\r\n");

            sb.append(String.format("VPN dialogs: %B\r\n",
                    isPackageInstalled("com.android.vpndialogs", context)));
            try {
                sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null));
            } catch (Throwable ex) {
                sb.append("Prepared: ").append((ex.toString())).append("\r\n")
                        .append(Log.getStackTraceString(ex));
            }
            sb.append(String.format("Permission: %B\r\n", hasPhoneStatePermission(context)));
            sb.append("\r\n");

            sb.append(getGeneralInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getNetworkInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getSubscriptionInfo(context));
            sb.append("\r\n\r\n");

            // Get settings
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            Map<String, ?> all = prefs.getAll();
            for (String key : all.keySet())
                sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n");
            sb.append("\r\n");

            // Write logcat
            OutputStream out = null;
            try {
                Log.i(TAG, "Writing logcat URI=" + uri);
                out = context.getContentResolver().openOutputStream(uri);
                out.write(getLogcat().toString().getBytes());
                out.write(getTrafficLog(context).toString().getBytes());
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n");
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ignored) {
                    }
            }

            // Build intent
            Intent sendEmail = new Intent(Intent.ACTION_SEND);
            sendEmail.setType("message/rfc822");
            sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "metehan.ozsoy@gmail.com" });
            sendEmail.putExtra(Intent.EXTRA_SUBJECT, "FilterEagle " + version + " logcat");
            sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            return sendEmail;
        }

        @Override
        protected void onPostExecute(Intent sendEmail) {
            if (sendEmail != null)
                try {
                    context.startActivity(sendEmail);
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }
    };
    task.execute();
}

From source file:br.ajmarques.cordova.plugin.localnotification.Restore.java

@Override
public void onReceive(Context context, Intent intent) {
    // The application context needs to be set as first
    LocalNotification.setContext(context);

    // Obtain alarm details form Shared Preferences
    SharedPreferences alarms = LocalNotification.getSharedPreferences();
    Set<String> alarmIds = alarms.getAll().keySet();

    /*//from  w ww  . j  av a  2s . c o  m
     * For each alarm, parse its alarm options and register is again with
     * the Alarm Manager
     */
    for (String alarmId : alarmIds) {
        try {
            JSONArray args = new JSONArray(alarms.getString(alarmId, ""));
            Options options = new Options(context).parse(args.getJSONObject(0));

            /*
             * If the trigger date was in the past, the notification will be displayed immediately.
             */
            LocalNotification.add(options);

        } catch (JSONException e) {
        }
    }
}

From source file:com.footprint.cordova.plugin.localnotification.Restore.java

@Override
public void onReceive(Context context, Intent intent) {
    // The application context needs to be set as first
    LocalNotification.setContext(context);

    // Obtain alarm details form Shared Preferences
    SharedPreferences alarms = LocalNotification.getSharedPreferences();
    Set<String> alarmIds = alarms.getAll().keySet();

    /*// w  w  w .java  2  s. c  o  m
     * For each alarm, parse its alarm options and register is again with
     * the Alarm Manager
     */
    for (String alarmId : alarmIds) {
        try {
            JSONArray args = new JSONArray(alarms.getString(alarmId, ""));
            Options options = new Options(context).parse(args.getJSONObject(0));

            /*
             * If the trigger date was in the past, the notification will be displayed immediately.
             */
            LocalNotification.add(options, false);

        } catch (JSONException e) {
        }
    }
}

From source file:eu.faircode.netguard.Util.java

public static void sendLogcat(final Uri uri, final Context context) {
    AsyncTask task = new AsyncTask<Object, Object, Intent>() {
        @Override// w w  w  .j  a v a 2 s .  c  om
        protected Intent doInBackground(Object... objects) {
            StringBuilder sb = new StringBuilder();
            sb.append(context.getString(R.string.msg_issue));
            sb.append("\r\n\r\n\r\n\r\n");

            // Get version info
            String version = getSelfVersionName(context);
            sb.append(String.format("NetGuard: %s/%d\r\n", version, getSelfVersionCode(context)));
            sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
            sb.append("\r\n");

            // Get device info
            sb.append(String.format("Brand: %s\r\n", Build.BRAND));
            sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
            sb.append(String.format("Model: %s\r\n", Build.MODEL));
            sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
            sb.append(String.format("Device: %s\r\n", Build.DEVICE));
            sb.append(String.format("Host: %s\r\n", Build.HOST));
            sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
            sb.append(String.format("Id: %s\r\n", Build.ID));
            sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context)));

            String abi;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
                abi = Build.CPU_ABI;
            else
                abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?");
            sb.append(String.format("ABI: %s\r\n", abi));

            sb.append("\r\n");

            sb.append(String.format("VPN dialogs: %B\r\n",
                    isPackageInstalled("com.android.vpndialogs", context)));
            try {
                sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null));
            } catch (Throwable ex) {
                sb.append("Prepared: ").append((ex.toString())).append("\r\n")
                        .append(Log.getStackTraceString(ex));
            }
            sb.append("\r\n");

            sb.append(getGeneralInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getNetworkInfo(context));
            sb.append("\r\n\r\n");

            // Get DNS
            sb.append("DNS system:\r\n");
            for (String dns : getDefaultDNS(context))
                sb.append("- ").append(dns).append("\r\n");
            sb.append("DNS VPN:\r\n");
            for (InetAddress dns : ServiceSinkhole.getDns(context))
                sb.append("- ").append(dns).append("\r\n");
            sb.append("\r\n");

            // Get TCP connection info
            String line;
            BufferedReader in;
            try {
                sb.append("/proc/net/tcp:\r\n");
                in = new BufferedReader(new FileReader("/proc/net/tcp"));
                while ((line = in.readLine()) != null)
                    sb.append(line).append("\r\n");
                in.close();
                sb.append("\r\n");

                sb.append("/proc/net/tcp6:\r\n");
                in = new BufferedReader(new FileReader("/proc/net/tcp6"));
                while ((line = in.readLine()) != null)
                    sb.append(line).append("\r\n");
                in.close();
                sb.append("\r\n");

            } catch (IOException ex) {
                sb.append(ex.toString()).append("\r\n");
            }

            // Get settings
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            Map<String, ?> all = prefs.getAll();
            for (String key : all.keySet())
                sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n");
            sb.append("\r\n");

            // Write logcat
            OutputStream out = null;
            try {
                Log.i(TAG, "Writing logcat URI=" + uri);
                out = context.getContentResolver().openOutputStream(uri);
                out.write(getLogcat().toString().getBytes());
                out.write(getTrafficLog(context).toString().getBytes());
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n");
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ignored) {
                    }
            }

            // Build intent
            Intent sendEmail = new Intent(Intent.ACTION_SEND);
            sendEmail.setType("message/rfc822");
            sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "marcel+netguard@faircode.eu" });
            sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat");
            sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            return sendEmail;
        }

        @Override
        protected void onPostExecute(Intent sendEmail) {
            if (sendEmail != null)
                try {
                    context.startActivity(sendEmail);
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }
    };
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}