file.delete() is not working
<p>In my application, I am calling a <code>Service</code> which performs the
<code>data-Uploading</code> to the server and after successfully upload, I want to
delete that uploaded file as if I don't delete that, it will upload
the same file as many times service runs. </p>

<p>To delete the uploaded file, I am using this method:</p>

<pre><code>String path = fileToBeUploaded.getPath();
File file = new File(path);
boolean delStatus= file.delete();
</code></pre>

<p>but it is not working. Please let me know what mistake I am doing here. </p>

<p>Here is my complete service class:</p>

<pre><code> public class UploadSurveyService extends Service implements SilentUploadSurveyListener{

   private static FileCache fileCache;
   private static boolean IS_REFRESHING_DATA = false;
   private static boolean NEXT_LAUNCH_SET = false;
   private  static boolean isFirstTime = true;

   private UploadSurveyAsyncTask updateLocationAsyncTask;
   private File fileToBeUploaded;

   public UploadSurveyService() {
   }

   @Override
   public IBinder onBind(Intent intent) {
     // TODO: Return the communication channel to the service.
     return null;
   }

   @Override
   public void onCreate() {
     super.onCreate();
     if(fileCache == null)
       fileCache = new FileCache(this);

     System.out.println("upload survey service created");
   }

   @Override
   public int onStartCommand(Intent intent, int flags, int startId) {
     System.out.println("upload service on start command");
     if(isFirstTime &amp;&amp; !NEXT_LAUNCH_SET){
       isFirstTime=false;
       scheduleNextLaunch();
     }
     else if(!IS_REFRESHING_DATA &amp;&amp; intent.hasExtra("FROM_ALARM")){
       if (Methods.checkInternetConnection(getApplicationContext(), false)) {
         IS_REFRESHING_DATA = true;

         System.out.println("service is checking the condition");

         fileToBeUploaded=  fileCache.getFileForUploading();

         if(fileToBeUploaded==null || !fileToBeUploaded.exists()){
           onUploadSurvey(false, null);
         } else {

           IS_REFRESHING_DATA=true;
           updateLocationAsyncTask = new UploadSurveyAsyncTask(getApplicationContext(),fileToBeUploaded, this);
           updateLocationAsyncTask.execute();
           Log.d("SK SERVICE", "executing upload survey task");
         }
       }
     } else {
        Log.d("SF SERVICE", "no internet");
        onUploadSurvey(false, null);
     }
     return super.onStartCommand(intent, flags, startId);
   }

   private void scheduleNextLaunch(){

     Calendar futureCalendar = Calendar.getInstance();
     Calendar currentCalendar = Calendar.getInstance();
     futureCalendar.set(Calendar.MINUTE,currentCalendar.get(Calendar.MINUTE) + 5);
     futureCalendar.set(Calendar.SECOND, 0);
     futureCalendar.set(Calendar.MILLISECOND, 0);
     //futureCalendar.set(Calendar.HOUR_OF_DAY,currentCalendar.get(Calendar.HOUR_OF_DAY)+1);

     AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
     Intent pendingIntent= new Intent(this, UploadSurveyService.class);
     pendingIntent.putExtra("FROM_ALARM", true);
     alarm.set( alarm.RTC_WAKEUP,futureCalendar.getTimeInMillis(),PendingIntent.getService(this, 0, pendingIntent, 0));
     NEXT_LAUNCH_SET = true;
     Log.d("SF Silent Upload", "repeat set ok");
   }

   @Override
   public void onUploadSurvey(boolean status, String message) {

     updateLocationAsyncTask = null;

     IS_REFRESHING_DATA = false;

     Log.d("SF SERVICE", "after finish async task");
     scheduleNextLaunch();

     if(status) {
       String path = fileToBeUploaded.getPath();
       File file = new File(path);
       boolean delStatus= file.delete();
       Toast.makeText(UploadSurveyService.this, "file deleted" + delStatus, Toast.LENGTH_SHORT).show();
     }
   }
 }
</code></pre>

<blockquote>
  <p>I also have declared the permission in manifest:</p>
</blockquote>

<pre><code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
</code></pre>