작동하지 않습니다, 여러 번 서비스 실행과 동일한 파일을 업로드합니다.File.delete를()는 내가 그것을 삭제하지 않는 경우 등이 업로드 된 파일을 삭제 원하는, 내가 서버에 <code>data-Uploading</code> 성공적 후 업로드를 수행하는 <code>Service</code>를 호출하고, 내 응용 프로그램에서
String path = fileToBeUploaded.getPath();
File file = new File(path);
boolean delStatus= file.delete();
을하지만 그것은 작동하지 않습니다 :
나는이 방법을 사용하고, 업로드 된 파일을 삭제합니다. 제가 여기서하고있는 실수를 알려주십시오. 여기 내 완벽한 서비스 클래스입니다 :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 && !NEXT_LAUNCH_SET){
isFirstTime=false;
scheduleNextLaunch();
}
else if(!IS_REFRESHING_DATA && 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();
}
}
}
나는 또한 매니페스트 권한 선언 한
:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
허가를 선언 했습니까? –
@ Er.Arjunsaini 어느 허락? – Devraj
사용 권한 android : name = "android.permission.WRITE_EXTERNAL_STORAGE" –