code: def mobile_app(request):
      
  
      ctx = {}
      try:
          ua = request.META.get('HTTP_USER_AGENT', '')
  
          if "IonAndroid: gcmFrame" in ua:
              logger.debug("IonAndroid %s", request.user)
  
              ctx["is_android_client"] = True
              registered = "appRegistered:False" in ua
              ctx["android_client_registered"] = registered
  
              if request.user and request.user.is_authenticated:
                  """Add/update NotificationConfig object."""
                  import binascii
                  import os
                  from intranet.apps.notifications.models import NotificationConfig
                  from datetime import datetime
  
                  ncfg, _ = NotificationConfig.objects.get_or_create(user=request.user)
                  if not ncfg.android_gcm_rand:
                      rand = binascii.b2a_hex(os.urandom(32))
                      ncfg.android_gcm_rand = rand
                  else:
                      rand = ncfg.android_gcm_rand
                  ncfg.android_gcm_time = datetime.now()
  
                  logger.debug("GCM random token generated: %s", rand)
                  ncfg.save()
                  ctx["android_client_rand"] = rand
  
          else:
              ctx["is_android_client"] = False
              ctx["android_client_register"] = False
      except Exception:
          ctx["is_android_client"] = False
          ctx["android_client_register"] = False
  
      return ctx
docs: Determine if the site is being displayed in a WebView from a native application.