2012-03-18 4 views
1

근접 알림을 처리하는 앱에서 작업하고 있습니다. 근접 경고를 추가 할 수는 있지만 이러한 근접 경고를 제거 할 수는 없습니다. 전화와 가상 장치에서 코드를 모두 시험했지만 코드를 제거하지 못했습니다. 여기 Android 근접 알림 제거

내 코드입니다 :

데이터베이스 및 근접 경고에 저장된 위치가

saveButton.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View view) { 
         String title = titleText.getText().toString(); 
         if(title.matches("")){ 
          Toast.makeText(CurrentLocationActivity.this,"Please provide a Title",Toast.LENGTH_SHORT).show(); 
         } 
         else{ 
          saveLocation(saveProximityAlertPoint(title));            
          setResult(RESULT_OK);          
          Toast.makeText(CurrentLocationActivity.this,"Location Saved",Toast.LENGTH_SHORT).show();  
         } 
        } 
       }); 

    private void saveLocation(int unique_location_id) { 
       if (location == null) { 
        Toast.makeText(this, "No last known location",Toast.LENGTH_LONG).show(); 
        return ; 
       } 
       else{ 
        String title = titleText.getText().toString();      
        String type = typeSpinner.getSelectedItem().toString();           
        range = (int) (radius + POINT_RADIUS);  
        int unique_id = unique_location_id;  
        Double latitude = location.getLatitude(); 
        Double longitude = location.getLongitude(); 

        location_id = mDbHelper.createLocation(title, type, range, unique_id, latitude, longitude); 

        titleText.setText(""); 
        radiusBar.setProgress(0); 
       } 
      } 

    private int saveProximityAlertPoint(String title) { 
       if (location == null) { 
        Toast.makeText(this, "No last known location.",Toast.LENGTH_LONG).show(); 
        return 0; 
       } 
       else{ 
        Double latitudeProxAlert = location.getLatitude(); 
        Double longitudeProxAlert = location.getLongitude(); 
        int unique_location_id = addProximityAlert(latitudeProxAlert, longitudeProxAlert, title); 

        return unique_location_id; 
       } 
      } 

    private int addProximityAlert(double latitude, double longitude, String title) { 

       Intent intent = new Intent(PROX_ALERT_INTENT); 
       intent.putExtra(LOCAION_TITLE, title); 

       PendingIntent proximityIntent = PendingIntent.getBroadcast(this, ++pending_intent_unique_id , intent, 0); 

       locationManager.addProximityAlert(latitude, longitude, range, PROX_ALERT_EXPIRATION, proximityIntent); 

       IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
       registerReceiver(new ProximityIntentReceiver(), filter); 
       Toast.makeText(this, "Proximity has been added for " + title + " with unique_id " + pending_intent_unique_id, 
         Toast.LENGTH_LONG).show(); 

       SharedPreferences.Editor editor = preferences.edit(); 
       editor.putInt("UNIQUEID", pending_intent_unique_id); 
       editor.commit(); 
       return pending_intent_unique_id; 
      } 

그리고 난 근접 그것은이다

public boolean onContextItemSelected(MenuItem item) {     
      switch(item.getItemId()) { 
      case R.id.menu_delete: 
       AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); 

       Cursor proxRemoveCursor = mDbHelper.fetchLocation(info.id); 
       removeProximityAlert(proxRemoveCursor.getInt(proxRemoveCursor.getColumnIndexOrThrow(DBAdapter.KEY_UNIQUE_LOCATION_ID))); 

       mDbHelper.deleteLocation(info.id); 

       proxRemoveCursor.close(); 

       return true; 
} 

    private void removeProximityAlert(int unique_id) { 

      String context = Context.LOCATION_SERVICE; 
      LocationManager locationManager = (LocationManager) getSystemService(context); 

      Intent anIntent = new Intent(REMOVE_PROXIMITY); 
      PendingIntent operation = 
       PendingIntent.getBroadcast(getApplicationContext(), unique_id , anIntent, 0); 
      locationManager.removeProximityAlert(operation); 
     } 
     } 

경고를 제거하려고 다른 활동을 추가 한 활동 조금 긴 코드가 있지만 내 질문에 맞는 가장 짧은 방법입니다. 도움을 Thnx.

답변

3

해결했습니다! 문제는 addProximityAlert()removeProximityAlert()에있는 의도 객체에 보내는 동작이 일치하지 않는다는 것입니다. 이제 실수를 수정 한 후 근접 경고를 제거 할 수 있습니다.

+0

마지막 코드를 보여 주면 문제를 어떻게 해결했는지 확인할 수 있습니까? – deucalion0

+1

의도 intIntent = 새로운 의도 (REMOVE_PROXIMITY); 의도 의도 = 새로운 의도 (PROX_ALERT_INTENT) ;. 내 최종 코드가 거기에있다. 문제는; REMOVE_PROXIMITY와 PROX_ALERT_INTENT가 일치해야합니다. 내가 처음 시도했을 때 그들은 달랐다. 동일한 경우 근접 경고를 제거 할 수 있습니다. – mkeremkeskin

+0

나에게 답장을 보내 건배, 나는 이것을 고치려고 노력했다. – deucalion0

0

어떤 값이 REMOVE_PROXIMITY입니까?