title: Detect the Android device theme (is it dark or light)
body: <p>You can set the theme for your app, but I'm wondering if it's possible to find out which one is used by the device. Currently, my app uses <code>Theme.AppCompat.Light</code>. I'd like to avoid changing the theme.</p>
  
  <p>P.S. I've already tried to set it to <code>Theme.DeviceDefault</code> and access its ID using reflection, but no luck so far.</p>
  
  <pre><code>try {
      setTheme(android.R.style.Theme_DeviceDefault);
  
      Class&lt;Context&gt; contextClass = Context.class;
      Method getThemeMethod = contextClass.getMethod("getThemeResId");
      getThemeMethod.setAccessible(true);
      Log.d("Test", "" + getThemeMethod.invoke(this)); // Always returns 0
  
      PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
      Log.d("Test", getResources().getResourceEntryName(packageInfo.applicationInfo.theme)); // Returns 'Theme.DeviceDefault'
  } catch (Exception e) {
      Log.d("Test", "exception", e);
  }
  </code></pre>