List of usage examples for android.app Activity getFilesDir
@Override
public File getFilesDir()
From source file:Main.java
public static void saveJsonToFile(String toSave, String filename, Activity currActivity) { // check if the file exists File dir = currActivity.getFilesDir(); File file = new File(dir, filename); if (file.exists()) { file.delete();/*from w ww .j a v a 2 s .c om*/ } FileOutputStream outputStream; try { outputStream = currActivity.openFileOutput(filename, Context.MODE_APPEND); outputStream.write(toSave.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static String getCrop(Activity activity, String name) { Bitmap bmp = getCrop(activity);// w ww . ja v a 2 s . c o m File file = new File(activity.getFilesDir(), name); FileOutputStream fileOutput = null; try { fileOutput = new FileOutputStream(file); } catch (FileNotFoundException e) { Log.e("golfpad", e.getMessage()); } bmp.compress(CompressFormat.JPEG, 50, fileOutput); return file.getAbsolutePath(); }
From source file:Main.java
public static void saveAccount(Activity act, String account, String psw) { String str = account + "," + psw; Properties localProperties = new Properties(); localProperties.put("account", str); try {/*from ww w. ja v a2 s . c o m*/ File file = new File(act.getFilesDir() + "/accout.cfg"); if (!file.exists()) file.createNewFile(); FileOutputStream localFileOutputStream = act.openFileOutput("account.cfg", Context.MODE_PRIVATE); localProperties.store(localFileOutputStream, ""); localFileOutputStream.close(); } catch (Exception localException) { localException.printStackTrace(); } }
From source file:com.mercandalli.android.apps.files.main.Config.java
public static Bitmap getUserProfilePicture(Activity activity) { File file = new File(activity.getFilesDir() + "/file_" + getUserIdFileProfilePicture()); if (file.exists()) { return BitmapFactory.decodeFile(file.getPath()); } else if (NetUtils.isInternetConnection(activity)) { FileModel.FileModelBuilder fileModelBuilder = new FileModel.FileModelBuilder(); fileModelBuilder.id(getUserIdFileProfilePicture()); new TaskGetDownloadImage(activity, fileModelBuilder.build(), 100_000, new IBitmapListener() { @Override// w w w . j av a 2 s . c o m public void execute(Bitmap bitmap) { //TODO photo profile } }).execute(); } return null; }
From source file:org.wahtod.wififixer.utility.LogUtil.java
public static void sendLog(final Activity activity) { /*// ww w . j ava2s . co m * Gets appropriate dir and filename on sdcard across API versions. */ //File file = VersionedFile.getFile(context, LOGFILE); final File file = new File(activity.getFilesDir(), LOGFILE); dumpLog(activity, file); /* * Get the issue report, then start send log dialog */ AlertDialog.Builder issueDialog = new AlertDialog.Builder(activity); issueDialog.setTitle(activity.getString(R.string.issue_report_header)); issueDialog.setMessage(activity.getString(R.string.issue_prompt)); // Set an EditText view to get user input final EditText input = new EditText(activity); input.setLines(3); issueDialog.setView(input); issueDialog.setPositiveButton(activity.getString(R.string.ok_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (input.getText().length() > 1) sendIssueReport(activity, input.getText().toString(), file); else NotifUtil.showToast(activity, R.string.issue_report_nag); } }); issueDialog.setNegativeButton(activity.getString(R.string.cancel_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); issueDialog.show(); }
From source file:com.nuvolect.securesuite.data.ExportVcf.java
public static void emailVcf(Activity act, long contact_id) { String messageTitle = "vCard for "; String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager"; try {/*from w w w . j a v a2 s . com*/ String displayName = SqlCipher.get(contact_id, ATab.display_name); String fileName = displayName.replaceAll("\\W+", ""); if (fileName.isEmpty()) fileName = "contact"; fileName = fileName + ".vcf"; new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs(); File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName); writeContactVcard(contact_id, vcf_file); // Must match "authorities" in Manifest provider definition String authorities = act.getResources().getString(R.string.app_authorities) + ".provider"; Uri uri = null; try { uri = FileProvider.getUriForFile(act, authorities, vcf_file); } catch (IllegalArgumentException e) { LogUtil.logException(act, LogType.EXPORT_VCF, e); } //convert from paths to Android friendly Parcelable Uri's ArrayList<Uri> uris = new ArrayList<Uri>(); uris.add(uri); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName); intent.putExtra(Intent.EXTRA_TEXT, messageBody); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("path", vcf_file.getAbsolutePath()); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); act.startActivityForResult(Intent.createChooser(intent, "Share with..."), CConst.RESPONSE_CODE_SHARE_VCF); } catch (Exception e) { LogUtil.logException(act, LogType.EXPORT_VCF, e); } }
From source file:org.matrix.matrixandroidsdk.db.ConsoleMediasCache.java
/** * Compute the filesystem cache size/*ww w.ja v a2 s . com*/ * @param context * @return the medias cache size in bytes */ public static long cacheSize(Activity context) { long size = 0; String[] filesList = context.fileList(); for (String filename : filesList) { try { File file = new File(context.getFilesDir(), filename); size += file.length(); } catch (Exception e) { } } return size; }
From source file:com.gelakinetic.mtgfam.helpers.ZipUtils.java
/** * This method exports any data in this application's getFilesDir() into a zip file on external storage * * @param activity The application activity, for getting files and the like *///from w ww .j a va 2 s . co m public static void exportData(Activity activity) { /* Make sure external storage exists */ if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { ToastWrapper.makeAndShowText(activity, R.string.card_view_no_external_storage, ToastWrapper.LENGTH_LONG); return; } /* Check if permission is granted */ if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { /* Request the permission */ ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, FamiliarActivity.REQUEST_WRITE_EXTERNAL_STORAGE_BACKUP); return; } assert activity.getFilesDir() != null; String sharedPrefsDir = activity.getFilesDir().getPath(); sharedPrefsDir = sharedPrefsDir.substring(0, sharedPrefsDir.lastIndexOf("/")) + "/shared_prefs/"; ArrayList<File> files = findAllFiles(activity.getFilesDir(), new File(sharedPrefsDir)); File sdCard = Environment.getExternalStorageDirectory(); File zipOut = new File(sdCard, BACKUP_FILE_NAME); if (zipOut.exists()) { if (!zipOut.delete()) { return; } } try { zipIt(zipOut, files, activity); ToastWrapper.makeAndShowText(activity, activity.getString(R.string.main_export_success) + " " + zipOut.getAbsolutePath(), ToastWrapper.LENGTH_SHORT); } catch (ZipException e) { if (e.getMessage().equals("No entries")) { ToastWrapper.makeAndShowText(activity, R.string.main_export_no_data, ToastWrapper.LENGTH_SHORT); } else { ToastWrapper.makeAndShowText(activity, R.string.main_export_fail, ToastWrapper.LENGTH_SHORT); } } catch (IOException e) { ToastWrapper.makeAndShowText(activity, R.string.main_export_fail, ToastWrapper.LENGTH_SHORT); } }
From source file:com.android.argb.edhlc.Utils.java
public static Drawable getRoundedImage(Activity activity, String playerName, String playerDeck) { File p1CroppedImageFile = new File(activity.getFilesDir(), "image_" + playerName + "_" + playerDeck + ".png"); Bitmap bitmap;//from w w w . j a v a 2s . c om if (p1CroppedImageFile.isFile()) bitmap = BitmapFactory.decodeFile(p1CroppedImageFile.getAbsolutePath()); else bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.avatar_holder); RoundedAvatarDrawable roundedImage = new RoundedAvatarDrawable(Utils.getSquareBitmap(bitmap)); roundedImage.setAntiAlias(true); return roundedImage; }
From source file:eu.janmuller.android.simplecropimage.CropImage.java
public static int calculatePicturesRemaining(Activity activity) { try {// w ww . ja v a 2s. co m /*if (!ImageManager.hasStorage()) { return NO_STORAGE_ERROR; } else {*/ String storageDirectory = ""; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { storageDirectory = Environment.getExternalStorageDirectory().toString(); } else { storageDirectory = activity.getFilesDir().toString(); } StatFs stat = new StatFs(storageDirectory); float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F; return (int) remaining; //} } catch (Exception ex) { // if we can't stat the filesystem then we don't know how many // pictures are remaining. it might be zero but just leave it // blank since we really don't know. return CANNOT_STAT_ERROR; } }