Tag: java

retrofit 2.0b2 : How to get InputStream from the response?

I’m using Retrofit 2.0b2. After getting a response, I tried getting an InputStream from the response by : Response<JsonNode> response = call.execute(); InputStream is = response.raw().body().byteStream(); but the app keep throwing : java.lang.IllegalStateException: Cannot read raw response body of a converted body. at retrofit.OkHttpCall$NoContentResponseBody.source(OkHttpCall.java:184) at com.squareup.okhttp.ResponseBody.byteStream(ResponseBody.java:43) at … Despite the response returned correctly. What am […]

Sorting an array of filenames containing strings with numbers

For my project I need to download a zip file from an FTP server, which releases a new zip about 13 times a year. I need to download the latest file following the server’s naming convention: Prefix + release number (one or two digits) + year (two digits) + suffix + “.zip” for instance: ALFP1016F.zip […]

Android EditText with word-wrap but no hard returns

If I set SingleLine=true on an EditText widget, I get a single-line edit control that doesn’t allow hard returns to be inserted by the user (clicking Enter moves to the next field instead of inserting a new line). If I don’t set SingleLine=true, the user can insert hard returns. If I set layout_height=”wrap_content”, the EditText […]

Passing JSON data in get request as request body

Hi i have to send a get request to an url http://onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth with request body contains json object as shown below. {“goupid”:”some_variable” } Here is a section of java code for sending get request: URL url1=new URL(“http://onemoredemo.appspot.com/group?authToken=”+access_token+”&authMethod=oauth”); conn=(HttpURLConnection) url1.openConnection(); conn.addRequestProperty(“Content-type”, “application/x-www-form-urlencoded”); conn.setRequestMethod(“GET”); conn.setDoOutput(true); JSONObject jj=new JSONObject(); HttpGet get; get. jj.put(“groupid”, “testing@iritesh.com”); conn.addRequestProperty(“Content-TYpe”, “application/json”); conn.getOutputStream().write(jj.toString().getBytes()); conn.connect(); […]

Java annotation execute a method within the annotation declaration(usage for android)

I’m fairly new to the annotation terms. I have read some sources and came to the conclusion that non answered my question. Perhaps I googled using the wrong search. Perhaps I overlook, or mayhbe im just clueless.. Anyway here is the deal. I am busy writing an application that requires “role validation”. To do this […]

Accesing contents of res/raw programatically (Android)

I’m working on an app for Android with a few other people, and the primary content is specified by our designers as text files in a certain file format, which we then parse, process, and serve in the app. We’re currently storing them in res/raw. This makes things great for the designers because when they […]

Android layout previewer throws error when adding custom LinearLayout

I’ve defined a custom ViewGroup that extends the functionality of a LinearLayout: public class TestLayout extends LinearLayout { public TestLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.testlayout, this, true); } } The layout it inflates (testlayout.xml) looks like this: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”vertical” android:gravity=”center”> <Button android:id=”@+id/button1″ […]

How to Parse Date from GMT TimeZone to IST TimeZone and Vice Versa in android

I am working on a project that fetches Date/Time from backend in IST(Indian standard Time) as shown “2013-01-09T19:32:49.103+05:30”. However when i parse it using following DateFormat DateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSSZ”); followed by parsing.. Date date = sdf.parse(“2013-01-09T19:32:49.103+05:30”); System.out.println(“XYZ ==============>”+date); its Displaying date in GMT format as output i.e Wed Jan 09 14:02:49 GMT+00:00 2013. […]

Dagger 2 component dependencies

Is it possible to inject something into a module? I have 2 base modules / components: @Component(modules = {OkHttpModule.class}) public interface OkHttpComponent extends AppComponent { OkHttpClient provideOkHttpClient(); } @Module public class OkHttpModule { @Provides OkHttpClient provideOkHttpClient() { return mHttpClient; } } @Component(modules = {GsonModule.class}) public interface GsonComponent extends AppComponent { Gson provideGson(); } @Module public […]

When are ALL the cases when the onSaveInstanceState() method called?

All the sources I read have all mentioned couple of cases and concluded with “a few other cases”. What are ALL the cases when the onSaveInstanceState method called in a View/Activity?

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