This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Sense 'dev mode' possible?

 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an Android app which needs to connect to a remote server for some data.
During development, I connect a real device via USB to test/run the app. Since the server side too is being simultaneously developed, I also run the server in my local environment for dev testing.

The server URL and other parameters have been defined as constants. I am wondering if there is some mechanism which will automatically if the app code being run is in dev mode, i.e. device is connected to laptop via USB, or any other mechanism, so I can achieve the following



GWT offers a very convenient GWT#isProdMode(). Considering both Android and GWT frameworks, I was wondering if there is something similar available in Android
 
Saloon Keeper
Posts: 5712
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The approach I use is

isDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)

You might also want to use dev params when running in the emulator:

isEmulator = Build.FINGERPRINT.startsWith("generic")

A more elegant solution would be to keep all those parameters in separate properties files that would live in src/debug/res/values and src/release/res/values, respectively. Then Gradle does the work for you.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim. I will try it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!