6

मैं कई निकटता अलर्ट बनाने की कोशिश कर रहा हूं लेकिन मैं इसे काम करने के लिए नहीं मिल सकता ...क्या ब्रॉडकास्ट रिसीवर कई प्रसारण प्राप्त कर सकता है?

मुझे लगता है कि प्रसारण रिसीवर ओवरराइट हो जाता है और इस प्रकार केवल अंतिम प्रसारण को संभाला जा रहा है। तो अगर मैं केवल एक है जिसका आशय पिछले एक चेतावनी उत्पन्न होगा बनाया गया था द्वारा करीब दो अंक ... था

मैंने पढ़ा है कि मैं अनुरोध कोड का उपयोग करना चाहिए, लेकिन मुझे लगता है कि कैसे करना है पर पता नहीं है ...


लंबित उद्देश्य और प्रसारण रिसीवर की स्थापना के लिए मेरे विधि ...

private void addProximityAlert(double latitude, double longitude, String poiName, String intentfilter) { 

    Bundle extras = new Bundle(); 
    extras.putString("name", poiName); 
    Intent intent = new Intent(PROX_ALERT_INTENT+poiName); 
    intent.putExtras(extras);  
    PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, requestCode, intent, 0); 
    locationManager.addProximityAlert(
     latitude, // the latitude of the central point of the alert region 
     longitude, // the longitude of the central point of the alert region 
     POINT_RADIUS, // the radius of the central point of the alert region, in meters 
     PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
     proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected 
    ); 
    requestCode++; 
    IntentFilter filter = new IntentFilter(intentfilter); 
    registerReceiver(new ProximityIntentReceiver(), filter); 
} 

मेरे broadcastreceiver वर्ग

public class ProximityIntentReceiver extends BroadcastReceiver { 

private static final int NOTIFICATION_ID = 1000; 

@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); 

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);   

    Notification notification = createNotification();   
    notification.setLatestEventInfo(context, 
     "Proximity Alert!", "You are approaching: " +intent.getExtras().get("name"), pendingIntent);  
                     //here------------------------------------- 
    notificationManager.notify(NOTIFICATION_ID, notification); 

} 

private Notification createNotification() { 
    Notification notification = new Notification(); 

    notification.icon = R.drawable.androidmarker; 
    notification.when = System.currentTimeMillis(); 

    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;   
    notification.flags |= Notification.FLAG_INSISTENT; 

    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notification.defaults |= Notification.DEFAULT_LIGHTS; 
    notification.defaults |= Notification.DEFAULT_SOUND; 

    notification.ledARGB = Color.WHITE; 
    notification.ledOnMS = 300; 
    notification.ledOffMS = 1500; 

    return notification; 
} 

} 

क्या आप कृपया मेरी मदद कर सकते हैं ??? मैं वास्तव में इस के साथ अटक गया हूँ ...

किसी भी मदद की वास्तव में सराहना की जाएगी !!!

उत्तर

8

मैं सब के बाद काम मिल गया ...

वास्तव में मैं क्या तलाश कर रहा था: http://www.gauntface.co.uk/blog/2010/01/04/proximity-alerts-in-android/

संशोधन मैंने बनाया


private void addProximityAlert(double latitude, double longitude, String poiName) { 

    Bundle extras = new Bundle(); 
    extras.putString("name", poiName); 
    extras.putInt("id", requestCode); 
    Intent intent = new Intent(PROX_ALERT_INTENT); 
    intent.putExtra(PROX_ALERT_INTENT, extras); 
    PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT); 
    locationManager.addProximityAlert(
     latitude, // the latitude of the central point of the alert region 
     longitude, // the longitude of the central point of the alert region 
     POINT_RADIUS, // the radius of the central point of the alert region, in meters 
     PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
     proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected 
    ); 
    requestCode++;  
} 

private void initialiseReceiver() 
{ 
    IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
    registerReceiver(new ProximityIntentReceiver(), filter); 
} 

package michaels.pack; 

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 ProximityIntentReceiver extends BroadcastReceiver { 

private static final int NOTIFICATION_ID = 1000; 

@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 receiverrrrrrrrrrrrrrrrrr"); 
    } 
    else { 
     Log.d(getClass().getSimpleName(), "exiting"); 
    } 

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);   

    Notification notification = createNotification();   
    notification.setLatestEventInfo(context, 
     "Proximity Alert!", "You are approaching: " +intent.getBundleExtra("michaels.pack.ProximityAlert.").get("name"), pendingIntent);  
                     //here------------------------------------- 
    notificationManager.notify(intent.getBundleExtra("michaels.pack.ProximityAlert.").getInt("id"), notification); 

} 

private Notification createNotification() { 
    Notification notification = new Notification(); 

    notification.icon = R.drawable.androidmarker; 
    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.defaults |= Notification.DEFAULT_SOUND; 

    notification.ledARGB = Color.WHITE; 
    notification.ledOnMS = 300; 
    notification.ledOffMS = 1500; 

    return notification; 
} 

} 
+1

बस जाने के लिए आप सभी जानते हैं कि मैंने अपने मूल कोड पर एक अद्यतन पोस्ट किया है जिसमें गिटहब पर एक पूर्ण उदाहरण शामिल है: http: //www.gauntface.co.uk/pages/blog/2010/12/28/how-to-multiple-proximity-alerts-in-android/ –

+1

आप अपना कैसे हटा सकते हैं अलर्ट? मेरा बस निर्माण जारी रखें। :( – deucalion0

+0

यह थोड़ी देर हो गया है और मुझे वास्तव में याद नहीं आया कि मैंने क्या किया है। – mixkat

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^