Tag: java

Write enum with String to parcel

I had Parcelable enum like this: public enum Option implements Parcelable { DATA_BASE, TRIPS, BIG_PHOTOS, OLD_PHOTOS, FILTERS_IMAGES, CATEGORIES_IMAGES, PAGES, SOUNDS, PUBLIC_TRANSPORT, MAPS; public static final Parcelable.Creator<Option> CREATOR = new Parcelable.Creator<Option>() { public Option createFromParcel(Parcel in) { return Option.values()[in.readInt()]; } public Option[] newArray(int size) { return new Option[size]; } }; @Override public int describeContents() { return […]

How to format longs in android to always display two digits

I have a countdown timer which shows seconds from 60 to 0 (1 min countdown timer). When it reaches 1 digit numbers such as 9,8,7.. it shows 9 instead of 09. I tried using String.format(“%[B]02d[/B]”, x); where I converted x from long to string. It didn’t work. I want an equivalent of String.format(“%2d”, 1)

How can I use adb to uninstall an APK from multiple connected devices?

This question already has an answer here: How can I adb install an apk to multiple connected devices? 16 answers

How to scan QRCode in android

I found a tutorial on how to scan a barcode. But in my application I have to scan a QR code. How can I a scan QR code in Android?

HttpClient redirecting to URL with spaces throwing exception

I am accessing a URL that’s redirecting me to a URL with spaces in it. (Using HttpClient 4.x) How do I prevent this from throwing an error (replacing the spaces with %20 not +) 08-06 02:45:56.486: WARN/System.err(655): org.apache.http.client.ClientProtocolException 08-06 02:45:56.493: WARN/System.err(655): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557) 08-06 02:45:56.534: WARN/System.err(655): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) 08-06 02:45:56.603: WARN/System.err(655): at com.romcessed.romsearch.searchproviders.DopeRomsConnector$DownloadROMTask.doInBackground(DopeRomsConnector.java:636) 08-06 02:45:56.623: […]

Java android: appending a newline using TextView

I just want to add a new line somehow to my linear layout: layout = (LinearLayout) findViewById (R.id.layout); … //some other code where I’ve appended some strings already final TextView nline = new TextView(this); nline.setText(Html.fromHtml(“<br>”)); //i also tried: nline.setText(“\n”); layout.addView(nline); But this just adds a few spaces. Can someone help me out? Thanks.

how to parse JSONArray in android

I want to read this JSON lines but because it start with JSONArray im a little confused “abridged_cast”: [ { “name”: “Jeff Bridges”, “id”: “162655890”, “characters”: [ “Jack Prescott” ] }, { “name”: “Charles Grodin”, “id”: “162662571”, “characters”: [ “Fred Wilson” ] }, { “name”: “Jessica Lange”, “id”: “162653068”, “characters”: [ “Dwan” ] }, { […]

java.net.URLEncoder.encode encodes space as + but I need %20

This question already has an answer here: URLEncoder not able to translate space character 11 answers

Scrollview not scrolling down completely

I’m building a chat-like application that displays text the user inputs to the screen using a scrollview. What I’m doing is auto-scrolling the scrollview down as more text is appended to the screen. I’m using ScrollView my_scrollview = (ScrollView) findViewById(R.id.scroller); my_scrollview.fullScroll(ScrollView.FOCUS_DOWN); This seems to work, although for some reason, because the keyboard is usually on […]

What's the difference between DataOutputStream and ObjectOutputStream?

I’m learning about socket programming in Java. I’ve seen client/server app examples with some using DataOutputStream, and some using ObjectOutputStream. What’s the difference between the two? Is there a performance difference?

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