AppWidget & Android Wear

 

Foreword

An AppWidget is a standalone element of an application. It’s a view placed on the home screen enabling part of the application to be displayed, without having to be open.

 

Tagging

It is necessary to instantiate a new Tracker in your widget in order for your tagging to work.

 

AppWidget

To tag your AppWidget, you can simply carry out normal tagging in the “onUpdate” method of your AppWidget class:

package com.atinternet.atinternetdemo;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;

import com.atinternet.tracker.ATInternet;
import com.atinternet.tracker.Tracker;

public class DemoWidget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        Tracker tracker = ATInternet.getInstance().getTracker("widgetTracker");
        tracker.Gestures().add("WidgetUpdate").sendTouch();
    }
}
 

Android Wear

To tag your application for AndroidWear, you must carry out regular tagging during interpretation of “messages” sent by the watch to the phone with the method “onMessageReceived”:

package com.atinternet.androidwearableapp;

import com.atinternet.tracker.ATInternet;
import com.atinternet.tracker.Tracker;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.WearableListenerService;

public class ListenerService extends WearableListenerService {

    private Tracker tracker;

    @Override
    public void onCreate() {
        super.onCreate();
        tracker = ATInternet.getInstance().getTracker("wearTracker");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        super.onDataChanged(dataEvents);
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        super.onMessageReceived(messageEvent);
        tracker.Gestures().add("WearTouch").sendTouch();
    }

    @Override
    public void onPeerConnected(Node peer) {
        super.onPeerConnected(peer);
    }

    @Override
    public void onPeerDisconnected(Node peer) {
        super.onPeerDisconnected(peer);
    }
}
Was this post helpful?
Yes
No
Last update: 05/04/2018