Cover photo
Daniele Segato
Works at Neosperience
Attended University of Pavia
326 followers|364,743 views


Daniele Segato

Tools and Libraries  - 
Anyone writing native Android apps using Groovy in the place of Java?

Is it fully compatible with Android Studio and Gradle plugin?
Is there some issue with writing Android libraries?
Is Android Studio able to do all the cool stuff it do with Java? (resources preview, lint hints etc, etc...)
Any limitation / issue / caveats one should be aware of?

Thanks in advance to anyone willing to share their experience with it.
groovy-android-gradle-plugin - A Gradle plugin to support the Groovy language for building Android apps
Jorge Martín's profile photoDaniele Segato's profile photo
+Jorge Martín​ thank you for your comment, very appreciated
Add a comment...

Daniele Segato

I Got Mine  - 
EDIT: I take back most of this rant. The disconnection issue was caused by low battery mode and I've been a bit unlucky with it cause my first 3 tries with cast audio were with my device low on battery. The YouTube one still stand tough.

Really disappointed by my Chromecast Audio.

Not backward compatible (apps able to cast videos can't cast audio by default)
Lot of apps does not support it.
YouTube doesn't support audio cast (really?)
Device Audio Cast disconnects as soon as the device goes in stand by (screen shuts down).

This last thing really hangers me.

I've bought one cause i thought it was a great idea and i can't use it from the two sources i use the most to play music: YouTube and DS Audio.

you didn't make it backward compatible? ok, i guess, you must had your reasons. You can't force apps to integrate it? ok but you could definally make it work with YouTube. Issue with advertising? ok but at least provide a proper "screen" casting feature.

This is a rant, I know. But I didn't expected this from Google. You made me used to a different standard and you are lowering my expectations greatly lately.
Michael Perrigo's profile photoMike Gallagher's profile photoDaniele Segato's profile photoPravin Karandikar's profile photo
+Mike Gallagher​ yeah. I hope so. YouTube is partly a music service too.
Add a comment...

Daniele Segato

OnePlus 2  - 
I switched from a Nexus 5 to a One Plus Two.

The Dialer App on Nexus used to let me search for nearby places since Lollipop.

For example you searched for "pizza" and it would give you phone contacts of nearby pizza you can call directly. It was even better then this and let you search for the actual name of the place. And not only for pizza or food. For ANYTHING.

I used this feature A LOT!

This feature is gone with One Plus 2 :(
It just look into my contacts list which is a shame...

Anyone know if there's a way to get that behavior back?
I guessed it's because of the double sim: they wrote another dialer app, but I only use a single SIM.

Please help.

#dialerapp #nearbyplaces
Daniele Segato's profile photoFrancesco A.'s profile photo
Right. You can just update it yourself periodically, just a workaround but better than nothing 
Add a comment...

Daniele Segato

Shared publicly  - 
Use a fixed aspect ratio with the Percent Support Library 23.1
Pro-tip by +Ian Lake

The Percent Support Library ( makes it easy to set dimensions and margins in terms of a percentage of the overall space. In the 23.1 release (, it also gained the ability to set a custom aspect ratio via app:layout_aspectRatio.

This allows you to set only a single dimension, such as only the width, and the height will be automatically determined based on the aspect ratio you’ve defined, whether it is 4:3 or 16:9 or even a square 1:1 aspect ratio.

So building a navigation drawer header with a 16:9 background image would look like:
  <!-- The rest of your layout -->

You’ll note we use layout_widthPercent instead of layout_width - this ensures that the height is not erroneously set to 0dp before the first layout pass is done and ensures the aspect ratio is always correctly computed based on the current width.

So how did a 16:9 aspect ratio turn into 178%? Our target 16:9 aspect ratio can also be expressed as a 1.78:1 ratio or equivalently, a width 178% of the height. This is the format the layout_aspectRatio expects.

Of course, you can also define the aspect ratio in separate XML files with code such as:

<item name="header_aspectRatio" type="fraction">178%</item>

This makes it possible to change or reuse them across different form factors or layouts.

Material design designates a number of ratio keylines ( which you can use in your app, but you could also consider using this for list items (where you may be using ?android:attr/listPreferredItemHeight) with items such as a profile image or video thumbnail for a fixed aspect ratio.

You’ll be able to use this with PercentFrameLayout, PercentRelativeLayout, or through any custom ViewGroup using PercentLayoutHelper (
13 comments on original post
Add a comment...

Daniele Segato

Tools and Libraries  - 
Anyone know of a tool like Android Holo Colors that support Lollipop Material Design buttons with backward compatibility for older versions?
Daniele Segato's profile photo
Nevermind: AppCompatButton :)
Add a comment...

Daniele Segato

Shared publicly  - 
Must read for any Android Developer :)
Mastering Pro-guard for building Lightweight Android code
Fantastic article that covers some different parts of getting up and running with powerful parts of Pro-guard.

 Besides obfuscation, is anyone else leveraging pro-guard for it's code-cleaning power?

The most powerful, yet lightest weight crash reporting solution for iOS and Android
1 comment on original post
Bernie Eng's profile photoIvo Encarnação's profile photo
Add a comment...
Have him in circles
326 people
Daniele Cammareri's profile photo
Javier Jurado Mármol's profile photo
Valerio Manzoni's profile photo
Matteo Basini's profile photo
matteo mantovani's profile photo
謝啟榮's profile photo
Marcos Trujillo's profile photo
Jaime Fernández's profile photo
Lara Paulato's profile photo

Daniele Segato

Shared publicly  - 
We all, developers, know how to chose our servers http response codes in any occasion, right?

If you don't, or you want to check or you like to have, somewhere, a finally well written documentation about it to pass on who is learning it...

Here it is :)
What could be simpler than returning HTTP status codes? Did the page render? Great, return 200 . Does the page not exist? That's a 404 . Do I want to redirect the user to another page? 302 , or maybe 301 . I like to imagine that HTTP status codes are like CB 10 codes. “Breaker breaker, this is ...
View original post
Add a comment...

Daniele Segato

Shared publicly  - 
Google Play Services Dependency Hell starring App Invites

It's not a movie title... it's an experience I had with Google App Invites recently.

This error made me lose roughly 3 days of work.

All libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 8.3.0, 8.1.0. Examples include and

Everything starts with me getting back to a project for which I worked 1-2 months before with the intent of updating the dependency used by that project on one of our company libraries.

So I go on and change:

compile 'mycoolcompany:mycoollibrary:1.4.0'


compile 'mycoolcompany:mycoollibrary:1.5.0'

gradle sync....


This innocent line in depencencies turn red:
compile ''
with the error I wrote above.

first tough: oh right! my cool library switched to play services 8.3.0

let's switch to 8.3.0 on this project too...
change it, gradle sync

SAME exact error....

ok, time to go deeper.

my app use these 2 play services dependencies: fitness and appinvite
the cool library use these two: analytics and location

no other dependencies in my project use any other play services libraries.

the error (I red it carefully at this point) said that the problem was with "measurement" part of play services, so which of my dependencies brough that in?

time to drop on the command line:

./gradlew app:dependencies --configuration compile

| +--- -> 8.3.0
| | \---
| | \--- -> 23.1.1
| | \---
| \--- -> 8.3.0
| \--- (*)

what the.... !?

it is not brought in by anything. It's a DIRECT dependency which is NO WHERE to be found in my project

./gradlew app:dependencyInsight --configuration compile --dependency
\--- compile


[INSERT hours of painful try-something-crazy-gradle-sync-check-again-google-repeat cycle here, featuring: exclusion of transitive dependencies, generated and intermediate files analysis in the build directory, random version changes of any of the dependency my project had, buildToolsVersion, compileSDK, target SDK, reboot computer (yep I was desperate), swearing etc....]

then I remembered something (like 24 hours of wasted work time later) when I added app invites to that app I had to do something weird: add google-services.json file in the app/ folder of my project.

At the time I just dismissed the fact: "it works, whatever". I didn't had much time to investigate.

When integrating app invites I had to add this to the root directory build.gradle file (not the one of my app):

buildscript {
repositories {
dependencies {
classpath ''
classpath ''

it must be that google-services dependencies that takes care of using the json file and do stuff.

As it turned out it also silently injected a dependency to my project to the

even knowing that I found no way of inspecting it, nor in the generated files nor in the gradle tools to inspect the project. I had to guess it! And figured out that if I was right changing the version of this google-services plugin it may had injected a more recent version of the play service library.

at the time the last version was: classpath '

and changing it finally fixed my project!

I blame Google for those hours. And I think this is a major bug.
But there's no place to file it, or I couldn't find any (
Honestly Google, WTF?!?

I'm writing this post in the hope that if any of you hit that same problem you'll be able to solve it quick, hopefully someone will find this by googling for the error message.
Add a comment...
I do soccer, basketball and squash.

All sports I can't carry my smartphone on me while I play.

I'm not very expert in health / activity monitoring devices (what's available, etc...)

I wish the app would suggest me which device to buy based on the activity I manually record (like, an actual device or just the "kind" of the device, like "what to look for").

That would be totally handsome, specially if the suggestion is not invasive/annoying :)
Ke Xiao's profile photo
Ke Xiao
+Allyson Gale This is a good idea for app dev in the future
Add a comment...

Daniele Segato

Help Center  - 

How do I get the currently connected Google Account on the Google Client?

Many Google Applications allow you to switch between Google Accounts and show you the currently connected account.

For example Google Fit, Gmail, Google+, etc...

From the perspective of the code I call .connect() on the Google Client and enter a loop of
- connection failed
- launch automatic resolution
- get activity result
- retry connect

until I finally connect.
This is documented in many places, here for example:

On the UX side what happens is that the user is presented with multiple dialogs asking every time something different.

One of the dialog ask to chose an Account between the ones available on the phone (it probably automatically resolve without user interaction if there's only one account configured).

How do you query the Google Client to know which account is currently connected?

I found no documentation about it anywhere.

The closest thing I found is this:

but I do not create the picker, it's something completely handled by the Play Services in the procedure I described above.

Thank you
Daniele Segato's profile photoIstván Maczkó's profile photoSoussi Mohamed's profile photoMartin McCaulley's profile photo
+Michael Pearce not sure if trolling or not, I reply just in case you are not.

For the same reason Google apps need it.
- showing the user which account he is using
- knowing, in my app, which account it is in use so that I can handle account switches (some Google Fit data I get from google is used by my app, if I can't detect the user changed account I end up mixing data that don't belong togheter)
Add a comment...

Daniele Segato

Shared publicly  - 
Doze mode for dummies
Understanding what Doze mode means for your app

Pro-tip by +Joanna Smith

Marshmallow introduced a new way for devices to preserve battery life by going idle. As an app developer, this means that there is now a difference between your app falling out of the foreground and the device itself being idle.

Before you start to panic about how to wake the device from Doze mode (, I recommend taking a moment to figure out if you even need to bust through that idleness.

Doze mode is different in that the entire device is taking a nap, not just the least-recently used apps (such is the case with App Standby). Doze mode is activated when the device is not plugged in, when the screen is locked, and when no motion has been detected for some time. These assumptions imply that the user has put down the device and walked away. So, when they come back and pick their phone up off the counter, it should not have dropped to 30% battery. It should, essentially, be in the exact state it was in when they placed it on the counter. Right?

So, the exceptions to Doze mode should be truly exceptional. There are two situations that I believe would qualify. First, if you have new information that is worth causing the user to walk over and look at their phone. Doze mode honors high-priority messages through Google Cloud Messaging (, so that you can respond to important moments, such as that new picture Mom just sent. Just don’t use it as an excuse to download a huge amount of data: try instead including the information needed to display a notification in the push message itself, and then fetch everything else when the user returns (and Doze mode ends).

And secondly, you may have work to do that is time-sensitive. But even AlarmManager ( is not exempt from Doze mode. However, just because the alarm will not fire during Doze mode does not mean it is lost. For example, an alarm set with setExact() will actually not trigger while Dozing, but will fire as soon as Doze mode exits. And for most use cases, this is actually fine, because if the user isn’t even holding their device, you probably don’t need to be syncing right now. But if you do have a task that is worth draining the user’s battery when they aren’t there, you can rely on setExactAndAllowWhileIdle() to wake your app even during Doze mode. Check out our previous pro-tip ( on working with alarms and background work for more details.

Ideally, Doze won’t disrupt your app flow too much. But spend some time thinking carefully about when your app may need special consideration. And after making any necessary changes, you can spend some more time testing your app. We’ve created several super helpful adb commands ( to make it easy to see how your app recovers when coming out of Doze mode.

So happy Dozing, developers. And continue to #BuildBetterApps
108 comments on original post
Add a comment...

Daniele Segato

Shared publicly  - 
Thanks Ian.

But... Am I the only one to think this should be FAR more easy?

Thinking about it this complexity is the very reason they had to introduce Doze in the first place.
And since there are ways to force your app to wake the device anyway I expect we will be in the same situation as pre-Doze after a while.

Creating a background service or something that does stuff in background should be as easy as declaring some kind of manifest and letting the system handle it.
A flowchart for background work, alarms, and your Android app
Pro-tip by +Ian Lake

For many apps, doing work in the background can be an important part of building a great experience. An alarm registered with AlarmManager ( is one way to schedule your app to be run sometime in the future, even if your app isn’t in the foreground. What alarm type and API should you use for your app or are alarms even the best option? Let’s go through some of the factors that should influence your opinion:

How often do you want to trigger?
For events less than 60 seconds apart, alarms aren’t the best choice: use the much more efficient Handler ( for frequent work.

Want to set a user visible alarm clock?
On API 21+ devices, new APIs allow you to set a user visible alarm via setAlarmClock(): the system UI may display the time/an icon and apps can retrieve the next alarm clock with getNextAlarmClock(). Note that alarms set with setAlarmClock() work even when the device/app is idle (similar to setExactAndAllowWhileIdle()): getting you as close to an exact wake up call as possible. For backward compatibility, you’ll follow the same guide below for a single alarm.

Wake up the device/app while idle (i.e., doze, app standby)?
On Android 6.0+ (API 23) devices, additional power-savings optimizations ( have been added in the form of Doze (triggered by a completely stationary, unplugged, and idle device) and App Standby (triggered by an unplugged device on idle apps that haven’t been used recently). You’ll use setAndAllowWhileIdle() for inexact and setExactAndAllowWhileIdle() for exact alarms if you need it to fire an alarm while in these idle states. If it can wait until the user returns to their device/your app, use the standard set() and setExact() to be the best Android citizen and save your user’s battery.

(We’ll be talking more specifically about Doze and App Standby later!)

Just a single alarm?
A single alarm can be set with the aptly named set() method. One thing to keep in mind is that on API 19+ devices when you target API 19+, the system will be treated as inexact, potentially batching alarms together - the alarm will never go off before the time specified, but may go off afterwards. If you have some flexibility in the start time but have a hard deadline, consider using setWindow() to gain more control over the exact time period to be used.

You can use setExact() for a precisely timed single alarms on API 19+ devices, but use these only when the exact timing is required (such as with a calendar reminder).

Need to repeat at a constant rate?
For repeating alarms, batching is the key to good battery life. setInexactRepeating() does exactly that. Prior to API 19, you can use one of the INTERVAL_ constants (such as INTERVAL_HOUR to batch alarms of the same interval. On API 19+ devices, all repeating alarms (no matter what the interval) set with setInexactRepeating() will be batched.

You’ll note there’s also setRepeating() - similar to set() the behavior changes with API 19 from exact to inexact repeating alarms, meaning if you are on an API 19+ device and target API 19+, this functions identically to setInexactRepeating(). If you really need exact repeating alarms on API 19+, set an exact alarm with setExact() and schedule the next alarm once your alarm has triggered - keep in mind the battery implications though!

BUT WAIT: should you even use alarms?
If you want to be as battery efficient as possible (and you should!), consider using JobScheduler ( on API 21+ devices or GcmNetworkManager ( on all Google Play services enabled devices of API 9+.

Supporting both one off and periodic work, these APIs lack the ability to wake from idle, but gain the ability to wait for network access, wait until the battery is charging, take advantage of automatic backoff and retry, persist across reboots, and batch jobs across the system (meaning lower battery usage!).

That’s a lot of good reasons to use JobScheduler and GcmNetworkManager so consider them strongly in your push to #BuildBetterApps
72 comments on original post
Eric Kok's profile photoSalvador Gómez's profile photo
Strongly agree. 'Good' developers who are trying to implement good response in their background services (like the beacon detection you mentioned) have to jump through dozens of hoops and cluttered code with platform-specific calls, while the 'evil' developer can still wake a device and keep it occupied as nasty and badly as ever before.
Add a comment...
Daniele's Collections
Have him in circles
326 people
Daniele Cammareri's profile photo
Javier Jurado Mármol's profile photo
Valerio Manzoni's profile photo
Matteo Basini's profile photo
matteo mantovani's profile photo
謝啟榮's profile photo
Marcos Trujillo's profile photo
Jaime Fernández's profile photo
Lara Paulato's profile photo
  • University of Pavia
    Computer Science, 2002 - 2008
  • ITIS Q.Sella Biella
    Liceo Scientifico Sperimentale Progetto Brocca, 1997 - 2001
I’m a programmer with a degree in computer science. I use Linux for fun and at work.
I’m currently programming in Android and Java.
I use 
gentoo at home and debian at work.

I like anything technical, Manga and Anime.
Bragging rights
High school was fun, then I began to study... now it's fun, but more nerdy
I'm Software Engineer, an Android Programmer, Technical Architect and designer
Android, Java, Git, Linux, many other things...
  • Neosperience
    Software Engineer, 2011 - present
  • OpenReply
    Consultant & Technical Leader, 2008 - 2011
Basic Information
Daniele Segato's +1's are the things they like, agree with, or want to recommend.
Manual Camera

Limited time offer! 50% off - only till the end of January!Important: This app takes full advantage of Lollipop's Camera2 API, and therefore


Chiudi gli occhi e riaprili nel mondo di KIKO Rewards, un programma che premia la tua passione per KIKO e per il mondo della bellezza con in

Câmera do Google

A Câmera do Google captura fotos e vídeos rápida e facilmente e inclui modos de imagem criativos como Photo Sphere, Desfoque da lente e Pano


The 2048 app is a fun, addictive and a very simple puzzle game. Join the numbers and get to the 2048 tile!HOW TO PLAY: Swipe (Up, Down, Left

Orario Treni PRO

Applicazione con widget per la consultazione degli orari dei treni italiani, ricerca treni e molto altro!☆ Comprende treni di Trenitalia, Tr

Thread Scheduling in Android

This post will give an overview of how thread scheduling works in Android, and will briefly demonstrate how to explicitly set thread priorit

Keyboard shortcuts - Hangouts Help

Format your messages Use the following keyboard shortcuts before you type a new message to add formatting. &lt;th width=&lt;/table...


DevDrawer is a widget based app for developers who are constantly installing / uninstalling / clearing data on their projects.I find myself

Publish an aar file to Maven Central with Gradle

Publish an aar file to Maven Central with Gradle


Do you like pushing buttons and shouting at your friends? Do you like discharging Clip-jawed Fluxtrunions? If you answered yes, or no, then

Ultimate Tic-Tac-Toe Online

Clean and simple Ultimate Tic-Tac-Toe against your friends! 9x9 boxes with an extra set of rules for extra fun! What is Ultimate Tic-Tac-Toe

PhotoHunt: End-to-end Google+ Platform sample application

Google+ Platform; Quickstart. Android · iOS · C# /.NET · Go · Java · JavaScript · PHP · Python · Ruby · PhotoHunt Sample · Android · C# /.NE

Duolingo: Learn Languages Free

Learn Spanish, French, German, Portuguese, Italian, and English. Totally fun and 100% free."Among apps for learning or practicing a language

Hangouts (replaces Talk)

Hangouts brings one-on-one and group conversations to life with photos, emoji, and video calls for free. Connect with friends across compute


A place for Android fans everywhere to meet, share and get the latest on all things Android.

SwiftKey 3 Keyboard

Unlock your typing potential.✮✮✮50% off holiday sale✮✮✮Get SwiftKey 3 – the best keyboard on Android! #1 selling app in 38 countries - over

Camera ZOOM FX

★★★★★ &quot;The Best Camera App for Android&quot; - lifehacker ★★★★★&gt;&gt; &quot;The Best Camera App for Android&quot; - lifehacker &gt;&gt; &quot;Grab this to show off to you

Uno dei migliori ristoranti messicani dove sono mai stato! La cucina messicana e' davvero ottima. Nel menu' i piatti piccanti sono indicati cosi' che si possano evitare se non piace. Provate la salsa Guacamole, tra i contorni, fatta in casa e davvero ottima. Nachos, Fajitas, insalate di cactus, Tacos, Chili e zuppe. Il menu' e' vario. All'arrivo ci hanno portato dei nachos (patatine) con salsa piccante e i menu. Ci hanno chiesto se volevamo un aperitivo che abbiamo preso (quello della casa, sostanzialmente un sorbetto alla tequila davvero buono! Che quasi si potrebbe prendere tra antipasto e secondo per aiutarsi con le porzioni abbondanti) Al momento di ordinare ho scelto un classico e ho ordinato Nachos tipici (non piccanti) e Fajitas al Manzo con contorno Guacamole e Formaggio fuso, L'antipasto era servito su un letto di nachos e formaggio fuso. Cipolle, peperoni e carne trita. Davvero ottimo. Le fajitas sono arrivate nel classico pentolino in ghisa con 3 tortillas di piccole dimensioni e un piatto di crema di fagioli. Se non le riempite moltissimo facilmente vi servira' ordinare altre tortillas (2 euro = 3 tortillas). Assemblato il tutto e mangiato, davvero notevole. Tutto e' arrivato abbastanza rapidamente ma ad Agosto il locale non era del tutto pieno (sul menu' c'e' scritto che fanno tutto al momento e che c'e' un po' da aspettare e so da amici che il locale e' normalmente sempre pieno, quindi preparatevi ad attendere un po'). La birra della casa e' la San Miguel alla spina, non male. Il personale e' giovane e simpatico e il locale e' davvero caratteristico, lo vedete dalle foto :) tutto in tema. Il locale ha una particolarita' per chi ordina tequila boom boom :) non vi rovino la sorpresa! Provateci! O ordinatelo per un amico ignaro! I dolci non sono male ma non e' il piatto forte del locale. Come costi dipende molto da quello che ordinate. Per darvi un'idea: antipasto 7 euro, fajitas di manzo 12, birra 1 litro 7 euro. El Corral si trova sulla statale ed e' dotato di un buon parcheggio. Se vi piace la cucina messicana o volete provarla andate qui!
• • •
Public - 5 months ago
reviewed 5 months ago
Si mangia bene ma non ci sanno fare. È un posto che consiglio per la cucina! strepitosa e abbondante. La moglie del proprietario però a volte è scortese e fuori luogo. Sorvoltate e andateci, merita davvero (chiuso nei week end). Consiglio risotto in cagnone e tris di dolci.
Public - 10 months ago
reviewed 10 months ago
Una delle pizze più buone di tutto il biellese! Leggera e digeribile, gustosa e con ingredienti genuini. Ottima birra.
Public - 10 months ago
reviewed 10 months ago
5 reviews
Birreria storica, pareti con roccia a vista e atmosfera rustica ma elegante. La birra è ottima e a buon prezzo! Pizze e ristorante eccellenti! Provate le specialità alla birra! Ottima anche nel dopocena! Se ci andate a cena consiglio di prenotare anche fra settimana perché son sempre pieni ;-)
Public - 10 months ago
reviewed 10 months ago
Mangiato da Dio! In 2 abbiamo preso panelle da dividerci, spaghetti Cassaro (acciughe, tonno, soffritto e pangrattato... 10+ ma quanto erano buoni?) e spaghetti alle vongole veraci. Un bel vinello bianco della casa, acqua naturale e caffè (offerto)! Il tutto a soli 27 euro.. Meno di 15 a testa e siamo andati via pieni (porzioni generose) e soddisfatti! Davvero ottimo! Sì trova a pochi passi dal palazzo di giustizia. La zona non è delle più belle (come molte a Palermo purtroppo) ma dentro è molto carino: muri con pietra a vista e soffitto in legno! Bagni puliti! Il proprietario molto simpatico e in gamba. Unica pecca abbiamo ricordato il vino a un cameriere perché non arrivava e chiamato per chiedere dei dolci e del caffè, ci avevano dimenticato :-P Ma sinceramente... Non é questo gran problema! Il cibo era fantastico e il prezzo incredibile! E poi c'era un cameriere al suo primo giorno, facilmente era dovuto a questo ;-) Non so valutare i dolci perché siamo arrivati tardi ed erano finiti. Anzi grazie per averci accettato quasi alle 15! Se siete da quelle parti fateci un salto ;-) io ci andrei tutte le settimane se non abitassi a più di 1000km ;-)
• • •
Public - 2 years ago
reviewed 2 years ago