private void onSetAsWallpaper() {
   WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
   if (wallpaperFile == null || !wallpaperFile.exists()) {
     Snackbar.make(rootLayout, R.string.fab_snack_bar_image_not_cached, Snackbar.LENGTH_LONG)
         .show();
   } else {
     if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
       Bitmap wallpaper = BitmapFactory.decodeFile(wallpaperFile.getAbsolutePath());
       if (wallpaper != null) {
         try {
           wallpaperManager.setBitmap(wallpaper);
           if (floatingActionMenu.isOpened()) floatingActionMenu.close(true);
           Toast.makeText(this, "Image set as Wallpaper", Toast.LENGTH_SHORT).show();
         } catch (IOException io) {
           io.printStackTrace();
         }
       }
     } else {
       Uri cropWallpaperUri =
           FileProvider.getUriForFile(this, "com.pddstudio.fileprovider", wallpaperFile);
       if (cropWallpaperUri != null) {
         Intent cropIntent = wallpaperManager.getCropAndSetWallpaperIntent(cropWallpaperUri);
         startActivity(cropIntent);
       }
     }
   }
 }
  private void shareComicImage() {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    Bitmap mBitmap = mComicMap.get(sFavoriteIndex).getBitmap();
    try {
      String path =
          MediaStore.Images.Media.insertImage(
              getActivity().getContentResolver(), mBitmap, "Image Description", null);
      share.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
    } catch (Exception e) {
      try {
        File cachePath = new File(getActivity().getCacheDir(), "images");
        cachePath.mkdirs(); // don't forget to make the directory
        FileOutputStream stream = new FileOutputStream(cachePath + "/image.png");
        mBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        stream.close();

        File imagePath = new File(getActivity().getCacheDir(), "images");
        File newFile = new File(imagePath, "image.png");
        Uri contentUri =
            FileProvider.getUriForFile(
                getActivity(), "com.gadgetmonks.carntoonage.fileprovider", newFile);

        share.putExtra(Intent.EXTRA_STREAM, contentUri);
      } catch (IOException e2) {
        e.printStackTrace();
      }
    }
    if (PrefHelper.shareAlt()) {
      share.putExtra(Intent.EXTRA_TEXT, PrefHelper.getAlt(sFavorites[sFavoriteIndex]));
    }
    startActivity(Intent.createChooser(share, this.getResources().getString(R.string.share_image)));
  }
Esempio n. 3
0
 public static Uri getSoundUri(int not) {
   switch (not) {
     case 0:
       return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
     default:
       try {
         File file =
             new File(
                 Environment.getExternalStorageDirectory() + "/Animeflv/cache/.sounds",
                 getSoundsFileName(not));
         if (file.exists()) {
           file.setReadable(true, false);
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
             Uri uri =
                 FileProvider.getUriForFile(context, "knf.animeflv.RequestsBackground", file);
             context.grantUriPermission(
                 "com.android.systemui", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
             return uri;
           } else {
             return Uri.fromFile(file);
           }
         } else {
           Log.d("Sound Uri", "Not found");
           return getSoundUri(0);
         }
       } catch (Exception e) {
         e.printStackTrace();
         return getSoundUri(0);
       }
   }
 }
Esempio n. 4
0
 public Uri getTakePhotoUri() {
   File file = new File(getTakePhotoPath() + "IMG_" + fileDateFormat.format(new Date()) + ".jpg");
   file.getParentFile().mkdirs();
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
     return FileProvider.getUriForFile(mXmppConnectionService, CONVERSATIONS_FILE_PROVIDER, file);
   } else {
     return Uri.fromFile(file);
   }
 }
Esempio n. 5
0
 public static void shareReport(Context ctx) {
   Intent intent = new Intent(Intent.ACTION_SEND);
   intent.setType("text/html");
   intent.putExtra(Intent.EXTRA_SUBJECT, ctx.getString(R.string.subjectline));
   intent.putExtra(
       Intent.EXTRA_STREAM,
       FileProvider.getUriForFile(
           ctx,
           "de.onyxbits.fileprovider",
           new File(new File(ctx.getFilesDir(), MainService.HTDOCS), ZippedReportFilter.NAME)));
   ctx.startActivity(Intent.createChooser(intent, ctx.getString(R.string.sharevia)));
 }
Esempio n. 6
0
  /**
   * Open the book's real file in an application which will allow the user to read it. This will
   * also put the book at the top of the recents list.
   *
   * @param realm Instance of Realm to use.
   * @param book Book to open.
   * @param posToUpdate If not {@code -1}, then an {@link ActionEvent} will be fired
   */
  public static void openBookUsingIntent(Realm realm, RBook book, int posToUpdate) {
    if (!Util.checkForStoragePermAndFireEventIfNeeded(R.id.action_execute_deferred)) {
      // Defer this action while we ask for permission.
      setDeferredAction(
          params -> openBookUsingIntent(realm, (RBook) params[0], (int) params[1]),
          book,
          posToUpdate);
      return;
    }

    File file = Util.getFileFromRelPath(book.relPath);
    // Make the user aware if the underlying file doesn't exist.
    if (file == null) {
      SnackKiosk.snack(R.string.sb_err_file_not_found, Snackbar.LENGTH_SHORT);
      return;
    }

    // Construct intent to use to open the file.
    Intent newIntent = new Intent(Intent.ACTION_VIEW);
    newIntent.setDataAndType(
        FileProvider.getUriForFile(Minerva.get(), "com.bkromhout.minerva.Minerva.files", file),
        MimeTypeMap.getSingleton().getMimeTypeFromExtension(Util.getExtFromFName(file.getName())));
    newIntent.setFlags(
        Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

    try {
      // Try to open the book file in the app of the user's choice.
      // TODO Animate the clicked view to fill the screen as a transition out??
      Minerva.get().startActivity(newIntent);
      // Put book at the top of the recents list.
      realm.executeTransaction(
          tRealm -> {
            book.lastReadDate = Calendar.getInstance().getTime();
            book.isInRecents = true;
          });
      // If we have a position to update, fire an ActionEvent (NOT UpdatePosEvent!!).
      if (posToUpdate != -1)
        EventBus.getDefault().post(new ActionEvent(R.id.action_read, null, posToUpdate));
    } catch (ActivityNotFoundException e) {
      // Tell the user there aren't any apps which advertise the ability to handle the book's file
      // type.
      SnackKiosk.snack(R.string.sb_err_no_apps, R.string.dismiss, Snackbar.LENGTH_LONG);
    }
  }
  private void sendSound(int position) {

    String path = sounds[position].getPath().replace("/data/data/de.tuete.soundboard/files/", "");
    final File file = new File(getFilesDir(), path);
    Log.d(TAG, "File path: " + file.getPath());

    final Uri uri = FileProvider.getUriForFile(this, "com.mydomain.fileprovider", file);
    Log.d(TAG, uri.toString());

    final Intent intent =
        ShareCompat.IntentBuilder.from(this)
            .setType("audio/*")
            .setStream(uri)
            .createChooserIntent()
            //		    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    startActivity(intent);
  }
Esempio n. 8
0
        @Override
        public boolean onPreferenceClick(Preference preference) {
          String exportStr;
          try {
            exportStr = Parser.serializeSync(Preferences.exportToMessage());
          } catch (JsonProcessingException e) {
            Toast.makeText(context, R.string.preferencesExportFailed, Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            return false;
          }

          if (exportStr == null) return false;

          Log.v("Export", "Config: \n" + exportStr);
          File cDir = App.getInstance().getBaseContext().getCacheDir();
          File tempFile = new File(cDir.getPath() + "/" + TEMP_FILE_NAME);

          try {
            FileWriter writer = new FileWriter(tempFile);

            writer.write(exportStr);
            writer.close();

            Log.v(TAG, "Saved temporary config file for exportToMessage to " + tempFile.getPath());

          } catch (IOException e) {
            e.printStackTrace();
          }
          Uri configUri =
              FileProvider.getUriForFile(
                  App.getInstance(), "org.owntracks.android.fileprovider", tempFile);

          Intent sendIntent = new Intent();
          sendIntent.setAction(Intent.ACTION_SEND);
          sendIntent.putExtra(Intent.EXTRA_STREAM, configUri);
          sendIntent.setType("text/plain");

          context.startActivity(
              Intent.createChooser(sendIntent, context.getString(R.string.exportConfiguration)));
          Toast.makeText(context, R.string.preferencesExportSuccess, Toast.LENGTH_SHORT).show();

          return false;
        }