Snippets

Small pieces of code that can be copy/paste-ed on your project

Snippets, Solutions

Android Show HTML Bulleted List from strings.xml

If you search on the internet about how to show a bulleted list from strings.xml using HTML tags, most of the answers will say that you should use a WebView, or to use the bullet symbol directly, or other alternatives. And on some posts I even read that you can’t use <li> tag from HTML

, ,
Snippets, Solutions

How to get current flavor from gradle

 Figuring out how to pull the current flavor from gradle While working on an update for one of our games, I needed to figure out how to get the current flavor and use it in code. Since there are a lot of ways to do this, I chose to create a custom build config parameter and

, , ,
Snippets

Generate random number between 2 numbers

The following snippet will help you generate a random number in Java that is between 2 numbers (min and max). static Random random = new Random(); /** * Min is inclusive and max is exclusive in this case **/ public static int randomBetween(int min, int max) { return random.nextInt(max – min) + min; } Please

, ,
Snippets

Get screen size programatically in Android

So if you ever need to get the screen size(width and height) programatically on Android, note that there are a few options out there. Please see below some of them. Get Android screen size from DisplayMetrics The following snippet helps you load the screen size in Android using the Display class. This is quite old,

, , , , , ,
Snippets, Solutions

How to unzip Gzipped InputStream

If you are working with HttpURLConnection on Android then you might encounter strange InputStream outputs like when you have a strange character encoding even though on the server side everything seems ok. A problem I was encountered lately was when I needed to parse a RSS/Atom feed on Android. I was getting the following error:

, , , ,
Snippets, Solutions

Print Android signing key SHA in code

If you ever want to get the Android SHA (1/256), MD5 or the signing key used to sign your app for example you can use the following snippet. Important! Be aware that you should not print that in a production environment as it might leak sensitive data API 28> (Kotlin) Deprecated (Java) And the converter

, , , , , , , ,
Snippets, Solutions, Tutorial

Add links to a TextView in Android

Maybe you need to add links to a TextView on Android but you don’t want to use Linkify for some reasons and you also want that link to be opened when the user taps it. Here is a simple solution: yourTextView.setText(Html.fromHtml( “Text with a ” + “<a href=\”http://www.myandroidsolutions.com/\”>link to My Android Solutions</a> “)); // this is

, , , ,
Snippets, Solutions

Android: How To Change Hint’s Size

If you need to set a smaller hint for your edit text, you can set the hint this way: myEditText.setHint(Html.fromHtml( “<small><small><small>” + getString(R.string.hint) + “</small></small></small>”)); Also, you can set the size in the string resource file where is the string for the hint. <string name=”edit_text_hint”><font size=”15″>My hint string</font></string> and in the xml file just set

, , ,
Snippets

Get Android OS Version

If you ever need to get the version of the OS on which your app runs, you can try this out: android.os.Build.VERSION.SDK_INT And you can use it against(for more check this out): android.os.Build.VERSION_CODES.[BASE-KITKAT]   Finally you end up with something like: if(android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.HONEYCOMB){ // do whatever you want here }

, , ,
Snippets, Solutions, Tutorial

Add CardView to Android OS versions below L ()

You might notice the new CardView widget on Android L preview presentation. The view can be used to display text or images and has a nice shadow. You can add that view into your project even if you don’t have the minimum API level to “L”… to do that, follow the steps below: 1.  Edit your gradle.build

, , , ,
Snippets, Solutions

Errors after update to Android Studio 0.8

I have just updated my Android Studio to Android Studio 0.8.2. But, after the update I kept getting these 3 errors while I was trying to run my project: 1.  First error Error:Execution failed for task > java.io.FileNotFoundException: C:\Program Files (x86)\Android\android-studio\sdk\tools\proguard\proguard-android-optimize.txt (The system cannot find the path specified) 2. Second error (this happened only after the

, ,
Snippets, Solutions

Share image Intent

Whenever you need to share an image from the external storage you can use the startActivity method and an Intent to do that. Doing so, the user will be able to chose whatever app he likes to share the photo. Intent share = new Intent(Intent.ACTION_SEND); share.setType(“image/png”); share.putExtra(Intent.EXTRA_STREAM, Uri.parse(“file:///”+imagePath)); startActivity(Intent.createChooser(share, “Share Image”)); If you don’t append the

, , ,
Snippets, Solutions

Android Gradle & Manifest merge

[Deprecated] This post is now deprecated, the Manifest Merger has changed since my first post. You can find more about this on the android developers site. Manifest file & Gradle If you started using Android Studio and implicitly Gradle, or you just started using Gradle with other IDEs (like Intellij for example), then maybe you

, , ,
Scroll to Top