android - proximity alert does not fire and notify -


does know issue cause fire alert not working when proximity radius? has been struggled week in solving issue , appreciated if can me out on issue or give me guide complete it.

mainactivity.java

import android.location.locationmanager; import android.os.bundle; import android.app.activity; import android.app.pendingintent; import android.content.context; import android.content.intent;   public class mainactivity extends activity {      private static final long point_radius = 150; // in meters     private static final long prox_alert_expiration = -1; // not expire     private static final string prox_alert_intent = "com.example.myalert";     private locationmanager locationmanager;     double latitude = 2.81202, longitude = 101.75989;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          locationmanager = (locationmanager) getsystemservice(context.location_service);          intent intent = new intent(prox_alert_intent);         pendingintent proximityintent = pendingintent.getbroadcast(this, 0, intent, 0);         locationmanager.addproximityalert(latitude, longitude, point_radius, prox_alert_expiration, proximityintent);      }  } 

proximityreceiver.java

import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.graphics.color; import android.location.locationmanager; import android.util.log;  public class proximityreceiver extends broadcastreceiver{     private static final int notification_id = 1000;      @suppresswarnings("deprecation")     @override     public void onreceive(context context, intent intent) {        string key = locationmanager.key_proximity_entering;        boolean entering = intent.getbooleanextra(key, false);        if (entering) {                   log.d(getclass().getsimplename(), "entering");            }else {                   log.d(getclass().getsimplename(), "exiting");            }            notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service);             intent notificationintent = new intent(context, mainactivity.class);            pendingintent pendingintent = pendingintent.getactivity(context, 0, notificationintent, 0);            notification notification = createnotification();            notification.setlatesteventinfo(context, "proximity alert!", "you near point of interest.", pendingintent);             notificationmanager.notify(notification_id, notification);     }      private notification createnotification() {         notification notification = new notification();         notification.icon = r.drawable.ic_launcher;         notification.when = system.currenttimemillis();         notification.flags |= notification.flag_auto_cancel;         notification.flags |= notification.flag_show_lights;         notification.defaults |= notification.default_vibrate;         notification.defaults |= notification.default_lights;         notification.ledargb = color.white;         notification.ledonms = 1500;         notification.ledoffms = 1500;         return notification;   } } 

androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.myalert"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.access_fine_location" />     <uses-permission android:name="android.permission.access_mock_location" />     <uses-permission android:name="android.permission.access_coarse_location" />     <uses-permission android:name="android.permission.vibrate" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.myalert.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>         <activity              android:name="proximityreceiver">         </activity>     </application>  </manifest> 

you have not set receiver in manifest, "proximityreceiver" not activity receiver. try this.

 <receiver android:name="proximityreceiver" >         <intent-filter>             <action android:name="com.example.myalert" />         </intent-filter>   </receiver> 

cheers.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -