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

MauroCerbai

Software Engineer

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
"One of the unique features of mobile applications is location awareness. Mobile users take their devices with them everywhere, and adding location awareness to your app offers users a more contextual experience. The location APIs available in Google Play services facilitate adding location awareness to your app with automated location tracking, geofencing, and activity recognition."
How to do that? Never been so simple:

Create a Google Api Client that use the api you need

mGoogleApiClient = new GoogleApiClient.Builder(this)
      .addApi(LocationServices.API)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this)
      .build();

Implements
  • GoogleApiClientConnectionCallbacks
  • GoogleApiClient.onConnectionFailedListener
  • LocationListener

Wait for a onConnected callback and ask for updates on location
mLocationRequest = LocationRequest.create()
      .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
      .setInterval(1000);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);

Wait for an other callback OnLocationChanged
@Override
public void onLocationChanged(Location location) {
  Log.d(LOG_TAG,"location: "+location.toString());
}

!NB: rembember to set:
  1. the permission on the manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

     2.Add the play services library in the manifest like this
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
     3. Add the lib to build gradle
compile 'com.google.android.gms:play-services:8.4.0'

Do not forget to call the appropiate method in order to deal with the activity lifecycle:
  @Override
    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    protected void onStop() {
        mGoogleApiClient.disconnect();
        super.onStop();
    }

My code is available here : https://bitbucket.org/mcmaur/googleaudacitylocationpart1


Happy coding!
Share
Tweet
Pin
Share
No commenti

In November 2014 I participated to the Smart Home Hackaton : a competition of ideas and fast prototyping promoted by the Energy@home Association and hosted and sponsored by i3P, the Incubator of the Politecnico of Torino.

In a weekend participants will be able to prototype their idea thanks to the consultancy experts and to pre-commercial prototypes: the connected whitegoods of Indesit Company, the smart meter of Enel Distribuzione, the home gateway and the service platform of Telecom Italia, the home automation devices of Flexgrid and Urmet.

I had the fortune to meet incredible people like Alberto Geniola,Riccardo Diomedi and Francesco Tuveri. They had a great idea in mind an with the help also of Elisabetta Fermo, Andrea Valenzano, Niccolò Giaccaglia, Francesco Tuveri, Tommaso Salvetti, Noushin Alishai, Luca Tarasco we develop a prototype to show to the judges. We presented a device aimed to be a personal assistant living that was able to register every food product and notify about expiry date, recommend the best wash cycle with the his camera capable of reading the labels of dress, to suggest recipe based on food availability, video surveillance and more. You can find our presentation here.


You can find more about the event here.
Share
Tweet
Pin
Share
No commenti
Share
Tweet
Pin
Share
No commenti
Just when you thought it was full of competitor, Samsung has announced it will launch its new craft to take tourists into space.

The famous brand announced yesterday during MWC (Mobile World Congress 2016 di Barcellona) he will join the space race to send passengers into space.


The craft is highly inspired by the Capsule Corporation spaceship of the famous Dragon Ball series. The similarity with the model in the picture is certainly no doubt.

It's design for 1 passenger only and will be ready for the summer of 2016.

The price of it is still uknown but it's obvious it wont be suitable for everyone: it is aimed at super rich thrill-seekers and celebrities, as well as researchers and commercial customers.
































This news is totally fake :) The product is real: Samsung Gear 360
Share
Tweet
Pin
Share
No commenti

My configuration:
  • Mars Gaming MC115 ATX Middle Tower
  • CPU Intel 1151 i3-6100
  • Toshiba 1TB
  • Corsair SSD 240GB Force LE
  • ASUS 1151 B150 Plus
  • Corsair Ddr4 2133 8Gb
  • Corsair 650W Vs650
I wanted a flexible system that could be easily upgraded during the time. In order to achieve that I got the latest socket available 1151 - Skylake so I can easily upgrade later and when it will be over I will get the most powerful i7 compatible. I chose to get a 1x8GB ddr4 ram so I can easily mount more later. Adding another 8GB I can reach 16GB that should be a lot of a while. Later, because of 4 slots I can add more and because of dual channel support I can add a different size ram so maybe it will be 16GB the common one and I can add it without problem.
Obviusly I added an sata3 SSD to reach the best from the operating system I have installed on it and then a 1TB of hdd to put all my documents and stuff.
The motherboard is affordable and the mouse support inside the BIOS is a gem.

I chose to dive the ssd in two partition and installing on it Chakra and Windows 10. I will use windows for part time gaming and programs not available on Linux sistem and I'm gonna use Chakra as my main distro of everyday stuff.
I like Chakra because it's always KDE centric with the latest update about software but the core parts are always tested until stable: so you can get the best of archlinux and the stability to use it everyday with semplicity.
Take a look at : chakraos.org
Share
Tweet
Pin
Share
No commenti

With an incredible 5 year of work by Javi Agenjo is born an indispensable tool, in my opinion, for developers who make extensive use of WebGL or for those in search of languages ​​very open and perfect to reach as many people as possible.

WebGLStudio is a platform to create interactive 3D scenes directly from the browser. It allows to edit the scene visually, code your behaviours, edit the shaders, and all directly inside a browser.

The technology of WebGL is nowadays available in every browser and make the most of it is a categorical imperative for the success of a great program. Thanks to the work of Javi Agenjo, a professor of the University Pompeu Fabra at Barcelona, this is simpler: the visual editor designed and implemented throughout the 3d graphics allows the management of objects in real time with the mouse and keyboard and the application of special effects on them like lights and shadows.
In addition it is possible  through a graphical interface specially developed to tie objects and effects and/or javascript script easily and without worrying about coding. The project is open source on github https://github.com/jagenjo/webglstudio.js. 


The invitation to all is to try it and willing to contribute to its growth.
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