Tag: java

Changing locale programmatically not working in some devices

I’ve the following piece of code: /** * Sets a new Locale for the APP. * @param newLocale – Valid new locale. */ private static void setLocale( String newLocale ) { Locale locale = new Locale( newLocale ); Locale.setDefault( locale ); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration( config, context.getResources().getDisplayMetrics() ); } Simple. […]

“R cannot be resolved to a variable” just after creating android project?

This question already has an answer here: “R cannot be resolved to a variable”? [duplicate] 30 answers

Android API 23 – HttpClient 4.X repackaged

Disclaimer I know we shouldn’t use HttpClient on Android anymore In API 23 we have option to use useLibrary ‘org.apache.http.legacy’ I’d like to continue using HttpClient (also I maintain libraries and projects based on it) however, with API 23 the classes are gone. Well not gone with useLibrary workaround, but cannot be used to develop […]

What is the most widely used feed-parsing library for Android

I want to make an app which (amongst other things) can parse feeds loaded via the network. Given that the standard Android + Core Java libraries do not provide a feed parser service and I don’t want to write a one myself, can you nominate a Java feed parser which will work on a low-spec […]

Why Would Dependencies Be Included Only In Release Builds?

Starting with a brand-new Android Studio 2.2.3 project, accepting all defaults except opting out of AppCompat, I added two dependencies to app/build.gradle: apply plugin: ‘com.android.application’ android { compileSdkVersion 25 buildToolsVersion “25.0.0” defaultConfig { applicationId “com.commonsware.myapplication” minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName “1.0” testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’ […]

Not able to post messages from server : Google Cloud Messaging

I am reading about GCM and at same time I am trying the sample code given in docs (extras/google/gcm/gcm-server/) and extras/google/gcm/gcm-client/. Registration process of client (device) is working fine. But when I tried to send message to registered device its giving me error, even when one device is added or more than one device is […]

Java – Timer.cancel() v/s TimerTask.cancel()

In my Android application, I run a timer and cancel it on some other event: class MyTimerTask extends TimerTask { override boolean cancel() { … } override void run() { … } } … Timer t = new Timer(); t.schedule(new MyTimerTask(),…) … t.cancel(); I was expecting t.cancel() to automatically invoke MyTimerTask‘s cancel() method. But that […]

How edit/change View from layout in RemoteView or create RemoteView from View?

I create widget for Android application (in Java, of course). I have classic RemoteViews created from layout (using layout id) RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.view); and I need edit or change view (identify by id). In classic View is it easy, using findViewById function. View v = … //inflate layout R.layout.view View my = […]

Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?

I’m using Square’s Retrofit Client to make simple requests from an Android App. Like so: RestAdapter restAdapter = new RestAdapter.Builder() .setServer(Configurations.getInstance().plistMap.get(“PTBaseURL”)) .setRequestHeaders(new RequestHeaders() { @Override public List<Header> get() { List<Header> headers = new ArrayList<Header>(); Header authHeader = new Header(“Authorization”, authType + ” ” + UserManager.getInstance().currentUser.token); headers.add(authHeader); } return headers; } }) .build(); this.service = restAdapter.create(ClientInterface.class); […]

Measuring Download Speed with Java/Android

I am working on an Android app where I need to, as accurately as possible, measure the download speed of the current connection. Here’s the best method I could find so far (basically I start a timer, start downloading a Linux distro from a fast server, download around 200 kbytes, then stop the timer and […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.