最近我开始使用Gimbal SDK。我还在测试它。 但是我似乎无法得到它的基本响应。代码看起来很简单,文档也做得很好。我想在一项服务中运行Gimbal区域检测,只是让您知道您已进入一个区域开始。一个薄的万向节没有支持或论坛,很难找到答案。这是我的代码
Notify类只是预设的抬头通知,效果很好。
//我的MainActivity onCreate
中的主要代码 Notify = new NotificationHandler(this);
Intent intent = new Intent(getApplicationContext(), Service.class);
startService(intent);
Notify.Notify("Service started",1000);
//这是我的服务代码
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import java.util.Timer;
import java.util.TimerTask;
public class Service extends IntentService {
Timer PlacesTimer;
TimerTask timerTask;
GimbalHandler Gimbal;
@Override
protected void onHandleIntent(Intent intent)
{
Log.d("XXX", "Intent Service executed");
StartTimer();
}
public Service()
{
super("MyService");
Gimbal = new GimbalHandler(this,this);
}
public void StartTimer()
{
PlacesTimer = new Timer();
initializeServiceTimerTask();
PlacesTimer.schedule(timerTask, 100, 500);
}
private void initializeServiceTimerTask()
{ timerTask = new TimerTask()
{
@Override
public void run()
{
Log.d("XXX","Timed");
}
};
}
}
//这是我简单的Gimbal课程
import android.app.Activity;
import android.app.IntentService;
import android.content.Context;
import com.gimbal.android.CommunicationManager;
import com.gimbal.android.Gimbal;
import com.gimbal.android.PlaceEventListener;
import com.gimbal.android.PlaceManager;
import com.gimbal.android.Visit;
public class GimbalHandler
{
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
Context ParentContext;
Activity Act;
IntentService Service;
NotificationHandler Notify;
public GimbalHandler(Context context,IntentService Service)
{
this.ParentContext = context;
//this.Act = activity;
this.Service = Service;
Notify = new NotificationHandler(ParentContext);
Gimbal.setApiKey(this.Service.getApplication(), "6e1536s92f3e");
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
Notify.Notify(visit.getPlace().getName().toString(),5);
}
@Override
public void onVisitEnd(Visit visit) {
Notify.Notify(visit.getPlace().getName().toString(),6);
}
};
placeManager = PlaceManager.getInstance();
placeManager.addListener(placeEventListener);
placeManager.startMonitoring();
CommunicationManager.getInstance().startReceivingCommunications();
}
}