static boolean downloadAllData ( ) { String data ; try { data = export ( ) . get ( ) ; } catch ( InterruptedException ex ) { Log . e ( WonderPush . TAG , "Unexpected error while exporting data" , ex ) ; return false ; } catch ( ExecutionException ex ) { Log . e ( WonderPush . TAG , "Unexpected error while exporting data" , ex ) ; return false ; } try { SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" , Locale . US ) ; sdf . setTimeZone ( TimeZone . getTimeZone ( "UTC" ) ) ; File folder = new File ( WonderPush . getApplicationContext ( ) . getFilesDir ( ) , "exports" ) ; folder . mkdirs ( ) ; String fn = "wonderpush-android-dataexport-" + sdf . format ( new Date ( ) ) + ".json" ; File f = new File ( folder , fn ) ; OutputStream os = new FileOutputStream ( f ) ; os . write ( data . getBytes ( ) ) ; os . close ( ) ; File fz = new File ( folder , fn + ".zip" ) ; ZipOutputStream osz = new ZipOutputStream ( new FileOutputStream ( fz ) ) ; osz . putNextEntry ( new ZipEntry ( fn ) ) ; osz . write ( data . getBytes ( ) ) ; osz . closeEntry ( ) ; osz . finish ( ) ; osz . close ( ) ; Uri uri = FileProvider . getUriForFile ( WonderPush . getApplicationContext ( ) , WonderPush . getApplicationContext ( ) . getPackageName ( ) + ".wonderpush.fileprovider" , fz ) ; Intent sendIntent = new Intent ( ) ; sendIntent . setAction ( Intent . ACTION_SEND ) ; sendIntent . putExtra ( Intent . EXTRA_STREAM , uri ) ; sendIntent . setType ( "application/zip" ) ; sendIntent . addFlags ( Intent . FLAG_GRANT_READ_URI_PERMISSION ) ; WonderPush . getApplicationContext ( ) . startActivity ( Intent . createChooser ( sendIntent , WonderPush . getApplicationContext ( ) . getResources ( ) . getText ( R . string . wonderpush_export_data_chooser ) ) ) ; return true ; } catch ( Exception ex ) { Log . e ( WonderPush . TAG , "Unexpected error while exporting data" , ex ) ; return false ; } }
Blocks until interrupted or completed .