휴지통으로 보내기가 아닌 완전 삭제
public static void deleteMailList(Context context, Account account, List<String> mailIds, GmailNetworkListener listener) {
try {
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, Collections.singleton(MAIL_SCOPE));
credential.setSelectedAccount(account);
Gmail service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build();
new DeleteMailListTask(account, service, mailIds, listener).execute();
} catch (Exception e) {
e.printStackTrace();
}
}
private static class DeleteMailListTask extends AsyncTask<Void, Void, Boolean> {
private Account account;
private Gmail service;
private List<String> mailIds;
private GmailNetworkListener listener;
public DeleteMailListTask(Account account, Gmail service, List<String> mailIds, GmailNetworkListener listener) {
this.account = account;
this.service = service;
this.mailIds = mailIds;
this.listener = listener;
}
@Override
protected Boolean doInBackground(Void... voids) {
if (listener == null) return Boolean.FALSE;
try {
BatchDeleteMessagesRequest deleteMessagesRequest = new BatchDeleteMessagesRequest().setIds(mailIds);
service.users().messages().batchDelete(account.name, deleteMessagesRequest).execute();
return Boolean.TRUE;
} catch (IOException e) {
e.printStackTrace();
listener.onFailure(e.toString());
}
return Boolean.FALSE;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (listener != null) {
listener.onSuccess(result);
}
}
}