android geofencing不会触发转换 [英] android geofencing not triggering the transitions
问题描述
大家好,
我正在尝试创建一个简单的地理围栏,并在我进入或退出地理围栏时尝试使用sysout。我尝试了一个简单的积极方案并使用Android开发者网站的geofencing模拟应用程序,但我没有得到任何回复。
我的主要活动看起来像这样.. < br $> b $ b
Hi All,
I am trying to create a simple geofence and trying to sysout when I am entrying or exiting the geo fence. I have tried a simple positive scenario and using the geofencing mock app from android developer site but I am not getting any responses.
My main activity looks like this..
public class MainActivity extends ActionBarActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, LocationListener,
com.google.android.gms.location.LocationListener,
LocationClient.OnAddGeofencesResultListener {
private LocationClient locationClient;
private ArrayList<Geofence> geoFenceList;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
geoFenceList = new ArrayList<Geofence>();
locationClient = new LocationClient(this, this, this);
locationClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
Geofence geofence = new Geofence.Builder().setRequestId("1")
.setCircularRegion(29.569332, 98.591356, 100)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER).build();
geoFenceList.add(geofence);
locationClient.addGeofences(geoFenceList, createPendingIntent(), this);
Toast.makeText(this, "Location client connected", Toast.LENGTH_SHORT).show();
}
private PendingIntent createPendingIntent() {
Intent intent = new Intent(this,
ReceiveGeofenceTransitionIntentService.class);
//Intent intent1 = new Intent("com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE");
return PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
@Override
public void onConnectionFailed(ConnectionResult result) {}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
}
意向服务类....
Intent service class ....
public class ReceiveGeofenceTransitionIntentService extends IntentService {
public ReceiveGeofenceTransitionIntentService() {
super("ReceiveGeofenceTransitionsIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
// Create a local broadcast Intent
Intent broadcastIntent = new Intent();
// Give it the category for all intents sent by the Intent Service
broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);
// Get the type of transition (entry or exit)
int transition = LocationClient.getGeofenceTransition(intent);
if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER) ||
(transition == Geofence.GEOFENCE_TRANSITION_EXIT))
System.out.println("Geofence Transition occured!!!!!!!!!!");
Toast.makeText(this, "Geofence Transition occured", Toast.LENGTH_SHORT).show();
{
}
}
}
我无法理解我哪里出错了。我在模拟地理围栏应用程序中给出了两个位置,其中一个是我正在构建地理围栏和其他相当远的地方。我可以看到我的设备在谷歌之间来回转换这两个位置,但我没有得到任何转换通知从我的申请。
我的清单是这样的....
I am not able to understand where I am going wrong. I am giving two locations in the mock geofence app one is around which I am building the geofence and other pretty far away.I could see the transition of my device in google to and fro between those two locations but I am not getting any transition notification from my application.
My manifest goes like this....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ocrvin"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"
/>
<service
android:name="com.aol.android.geofence.ReceiveTransitionsIntentService"
android:exported="false" >
</service>
<intent-filter >
<action android:name="com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE"/>
</intent-filter>
</receiver>
<activity
android:name="com.prototype.ocrvin.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
</manifest>
请帮助我,因为我被困在这里很多天。
Please help me as I am stuck in this for many days.
推荐答案
看看这个 google maps api 2 - Android Geofence仅适用于已打开的应用 - Stack Overflow [ ^ ]
give a look at this google maps api 2 - Android Geofence only works with opened app - Stack Overflow[^]
这篇关于android geofencing不会触发转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!