• Home
  • About me
  • Curriculum
  • Projects
Facebook Linkedin Twitter

MauroCerbai

Software Engineer


Hi everyone,
this Sunday my girlfriend and I did an amazing hike to the Vallée des Merveilles inside the Mercantour National Park in southern France.

Once you reach St-Dalmas-de-Tende take D6204 and follow the indication for Casterino. Once you see the Meches Lake you can park the car and start your journey.

Follow the indication for the refuge and then, only if you want, you can continue on. Just overtake the Lac Mouton you can find a trail going very uphill. Beware it is very steep.

A picture is worth a thousand words so...




... but a gps track is worth a thousand images
Download it here
Share
Tweet
Pin
Share
No commenti
For those who, like me, are experimenting with scikit learn
Share
Tweet
Pin
Share
No commenti

Share
Tweet
Pin
Share
No commenti

Firebase Analytics is a free app measurement solution that provides insight on app usage and user engagement

The new incredible thing Google pull from a hat. A incredible versatile library to analyze data and user engament. Would you like to try it out? Well listen here.

How to add firebase analytics to an android app

  • Create a project on the firebase console : https://console.firebase.google.com/
  • Enter your app's package name
  • Donwload the json file provided and insert into the "app" folder in your android project

  • Then add this inside dependencies on your root level build.gradle
  • classpath 'com.google.gms:google-services:3.0.0'

  • And this at the bottom of the app level build.gradle
  • apply plugin: 'com.google.gms.google-services'
  • Inside the same file but under "dependencies" you put this
compile 'com.google.firebase:firebase-core:9.2.1'

  • Declare a "FirebaseAnalytics" object on top of your MainActivity and the onCreate initialize it
  • mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Now you have your basic analytics data provided by the default event. You wanna add your own? Easy.

How to add your custom event

You create a bundle and insert all the information you need the event you want to control. Take a look at the FirebaseAnalytics.Param for suggested event.
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
That's it.
Share
Tweet
Pin
Share
No commenti

Share
Tweet
Pin
Share
No commenti

I attended Google I/O 2016 Extended in Milan.
Nice people, nice place (thanks Subito).


 But the news? mmmm I bet they could do better: they didn't show anything on the "conversational" Google Now nor the Google Home but they show up another crazy messaging app. The fourth I think. Hangouts will be kicked back in the line, again...
Come on Google, you can do better than this.


Thanks to Subito for their amazing stuff and hospitality.

Share
Tweet
Pin
Share
No commenti
Hey,
First of all take a deep look at part 1 available here.
Instead what's new on part 2? Well basically two things:

  • in part 1 we built an app to receive constant location update, so this time we will see how to get just on time only
  • we will see how activity recognition works

Part 1 - Getting the last known location

So, how to receive the last gps location once from the google api services?
Follow every instruction of the part 1 and then on the onConnected method write this:

@Override
public void onConnected(@Nullable Bundle bundle) {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (mLastLocation != null) {
        mLatitude.setText(String.valueOf(mLastLocation.getLatitude()));
        mLatitude.setText(String.valueOf(mLastLocation.getLongitude()));
    }
}

Part 2 - Activity Recognition

Add the permission in your app manifest file:
<uses-permission android:name="com.google.android.gms.permTission.ACTIVITY_RECOGNITION" />
Then to handle the activity recognition in background we are gonna use an IntentService:
public class DetectedActivitiesIntentService extends IntentService {
    protected static final String TAG = "detections_is";
    public static final String BROADCAST_ACTION = "com.maurocerbai.googleaudacitylocationpart2.BROADCASTACTION";
    public static final String ACTIVITY_EXTRA = "com.maurocerbai.googleaudacitylocationpart2.ACTIVITYEXTRA";
    public DetectedActivitiesIntentService() {
        super(TAG);
    }
    @Override    protected void onHandleIntent(Intent intent) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        Intent localIntent = new Intent(BROADCAST_ACTION);
        ArrayList <DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();
        localIntent.putExtra(ACTIVITY_EXTRA,detectedActivities);
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }
}
Don't forget to declare this service in the manifest:
<service android:name=".DetectedActivitiesIntentService"    android:exported="false" />
In your main activity build your goolge api connection as seen in part 1 but instead of location use activityrecognition as shown here:
private void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(ActivityRecognition.API)
            .build();
}
and add the possibility to listen to the broadcast you made before in a inner class:
class ActivityDetectionBroadcastReceiver extends BroadcastReceiver{
    @Override    public void onReceive(Context context, Intent intent) {
        ArrayList <DetectedActivity> detectedActivities = intent.getParcelableArrayListExtra(Constants.ACTIVITY_EXTRA);
        String res = "";
        for (DetectedActivity d:detectedActivities)
            res+=d.getType()+" "+d.getConfidence();
        text_label.setText(res);
    }
}
Then a this two method and link them to the button of the view:
public void requestActivityUpdateButtonHandler (View view){
    ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mGoogleApiClient,1000,getActivityDetectionPendingIntent()).setResultCallback(this);
}
public void removeActivityUpdateButtonHandler (View view){
    ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(mGoogleApiClient,getActivityDetectionPendingIntent()).setResultCallback(this);
}
Don't forget to handle the activity lifecycle adding this two method:
@Override protected void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(mActivityDetectionBroadcastReceiver,new IntentFilter(Constants.BROADCAST_ACTION));
}
@Override protected void onPause() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mActivityDetectionBroadcastReceiver);
    super.onPause();
}
DONE. Good luck testing it because the emulator is not very helpful in this case. Maybe using a GPX file you can simulate the movements using the latest version of the sdk tools.
You can find the code here : https://bitbucket.org/mcmaur/googleaudacitylocationpart2
Share
Tweet
Pin
Share
No commenti
Newer Posts
Older Posts

About me


Smiley face
Computer Science Degree, technology enthusiast, programmer, interested in startup & innovation, curious, precise & organized.

Follow Me

  • Facebook
  • Linkedin
  • Twitter
  • Bitbucket
  • Github

recent posts

Categories

  • dev
  • development
  • software
  • learn
  • learning
  • machine
  • machine learning
  • study
  • android
  • google
  • job
  • scikit
  • sklearn
  • app
  • udacity
  • gdg
  • google play
  • html
  • code
  • electronics
  • linux
  • script
  • uda
  • webgl
  • database
  • gdgmilano
  • help
  • open source
  • programming
  • smartphone
  • torino
  • weekend
  • work
  • workshop
  • 3d
  • firebase
  • gps
  • greatmind
  • hardware
  • location
  • personal computer
  • start up
  • .bashrc
  • GB
  • PS3
  • Vallée des Merveilles
  • action
  • analytics
  • audio
  • avi
  • bayes
  • books
  • bug
  • cpu
  • dinolib
  • docker
  • fake
  • ffmpeg
  • force
  • francaise
  • france
  • francia
  • free
  • gear 360
  • gglass
  • git
  • gitconfig
  • glass
  • hdd
  • hike
  • hiring
  • jenkins
  • joke
  • kde
  • kmix
  • magnetism
  • material
  • materialdesign
  • merge-it
  • messaging
  • microservices
  • mint
  • naive bayes
  • navigation drawer
  • nemo
  • nikola
  • nikolatesla
  • pc
  • ram
  • reading
  • refuge
  • samsung
  • space
  • spain
  • ssd
  • steam
  • tesla
  • unturned
  • valle delle meraviglie
  • veromix
  • versioning
  • windows
  • wizard
  • wolley
  • wolleybuy
  • xvid

Blog Archive

  • ottobre (1)
  • settembre (1)
  • gennaio (1)
  • novembre (1)
  • maggio (1)
  • aprile (1)
  • marzo (3)
  • febbraio (3)
  • gennaio (1)
  • novembre (7)
  • ottobre (4)
  • settembre (3)
  • agosto (1)
  • luglio (1)
  • settembre (1)
  • agosto (1)
  • giugno (2)
  • aprile (2)
  • marzo (1)
  • febbraio (3)
  • gennaio (2)
  • novembre (1)
  • agosto (2)
  • luglio (2)
  • giugno (3)
  • marzo (1)
  • novembre (1)
  • ottobre (1)
  • agosto (1)
  • giugno (1)
  • maggio (2)
  • marzo (2)
  • febbraio (1)
Facebook Linkedin Twitter Bitbucket Github

Created with by ThemeXpose | Distributed By Gooyaabi Templates