我想设置location(home)
,当我输入location(home)
时,应用会给我一个声音通知(嗨!我在家)。在eclipse中使用KitLocate
(geoFence)但它没有显示通知。我无法找到问题所在。我的MainActivity.java文件是
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
KitLocate.initKitLocate(this, "584da03d-18d7-4701-9808-eec48f65e797");
KLLocation.addGeofence(this, 31.54381f, 74.28253f, 5, KLGeofence.Type.IN,"Home");
KLLocation.registerGeofencing(this, GeofenceCallbackHandler.class);
}
@Override
protected void onStart() {
super.onStart();
KLApplication.onActivityStart(this);
}
@Override
protected void onStop() {
super.onStop();
KLApplication.onActivityStop(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
GeofenceCallbackHandler。的java
public class GeofenceCallbackHandler implements IKLGeofenceResponse{
@Override
public void geofenceIn(Context arg0, ArrayList<KLGeofence> arg1) {
new KLLocalNotification(arg0, "Hi, I am at home", R.drawable.ic_launcher).setDefaultSound(true).setContentTitle("Geofence in").send();
}
@Override
public void geofenceInArm(Context arg0, ArrayList<KLGeofence> arg1) {
// TODO Auto-generated method stub
}
@Override
public void geofenceOut(Context arg0, ArrayList<KLGeofence> arg1) {
// TODO Auto-generated method stub
}
@Override
public void geofenceOutArm(Context arg0, ArrayList<KLGeofence> arg1) {
// TODO Auto-generated method stub
}
}
的Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nabia.geofencetry"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<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_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<service android:name="com.kl.kitlocate.services.KLLocationService" android:label="KitLocate Service"/>
<service android:name="com.kl.kitlocate.services.KLAccelerometerService" android:label="KitLocate IDLE Service"/>
<service android:name="com.kl.kitlocate.services.KLRescueService" android:label="KitLocate Rescue Service"/>
<receiver android:name="com.kl.kitlocate.receivers.KLBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.nabia.geofencetry.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
请告诉我,我该怎么办?