Example usage for android.content Intent ACTION_ATTACH_DATA

List of usage examples for android.content Intent ACTION_ATTACH_DATA

Introduction

In this page you can find the example usage for android.content Intent ACTION_ATTACH_DATA.

Prototype

String ACTION_ATTACH_DATA

To view the source code for android.content Intent ACTION_ATTACH_DATA.

Click Source Link

Document

Used to indicate that some piece of data should be attached to some other place.

Usage

From source file:com.nogago.android.tracks.ImportActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();/*from ww  w.  j a v a2 s.  co m*/
    importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
    if (importAll) {
        path = FileUtils.buildExternalDirectoryPath("gpx");
    } else {
        String action = intent.getAction();
        if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
            Log.d(TAG, "Invalid action: " + intent);
            finish();
            return;
        }

        Uri data = intent.getData();
        if (!UriUtils.isFileUri(data)) {
            Log.d(TAG, "Invalid data: " + intent);
            finish();
            return;
        }
        path = data.getPath();
    }

    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof ImportAsyncTask) {
        importAsyncTask = (ImportAsyncTask) retained;
        importAsyncTask.setActivity(this);
    } else {
        importAsyncTask = new ImportAsyncTask(this, importAll, path);
        importAsyncTask.execute();
    }
}

From source file:com.google.android.apps.mytracks.ImportActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();/*from  ww  w  .  ja va  2 s. c  om*/
    importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
    if (importAll) {
        path = FileUtils.buildExternalDirectoryPath("gpx");
    } else {
        String action = intent.getAction();
        if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
            Log.d(TAG, "Invalid action: " + intent);
            finish();
            return;
        }

        data = intent.getData();
        /*
         * DDDD if (!UriUtils.isFileUri(data)) { // TODO Process URL Content (e.g.
         * for graphhopper.com) Log.d(TAG, "Invalid data: " + intent); finish();
         * return; }
         */
        path = getNameFromContentUri(data);
    }

    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof ImportAsyncTask) {
        importAsyncTask = (ImportAsyncTask) retained;
        importAsyncTask.setActivity(this);
    } else {
        importAsyncTask = new ImportAsyncTask(this, importAll, path, data);
        importAsyncTask.execute();
    }
}

From source file:com.google.android.apps.mytracks.io.file.ImportActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();/*from   w ww  .  ja va2  s.co m*/
    importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
    trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
    if (trackFileFormat == null) {
        trackFileFormat = TrackFileFormat.GPX;
    }

    if (!FileUtils.isExternalStorageAvailable()) {
        Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (importAll) {
        path = FileUtils.buildExternalDirectoryPath(trackFileFormat == TrackFileFormat.KML ? "kml" : "gpx");
        if (!FileUtils.isDirectory(new File(path))) {
            Toast.makeText(this, getString(R.string.import_no_directory, path), Toast.LENGTH_LONG).show();
            finish();
            return;
        }
    } else {
        String action = intent.getAction();
        if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
            Log.d(TAG, "Invalid action: " + intent);
            finish();
            return;
        }

        Uri data = intent.getData();
        if (!UriUtils.isFileUri(data)) {
            Log.d(TAG, "Invalid data: " + intent);
            finish();
            return;
        }
        path = data.getPath();
    }

    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof ImportAsyncTask) {
        importAsyncTask = (ImportAsyncTask) retained;
        importAsyncTask.setActivity(this);
    } else {
        importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, path);
        importAsyncTask.execute();
    }
}

From source file:jahirfiquitiva.iconshowcase.tasks.WallpaperToCrop.java

@Override
protected void onPostExecute(Boolean worked) {
    if (!wasCancelled) {
        if (toHide1 != null && toHide2 != null) {
            toHide1.setVisibility(View.GONE);
            toHide2.setVisibility(View.GONE);
        }//w w w .  j a v  a  2  s . co m
        if (worked) {
            dialog.dismiss();
            Intent setWall = new Intent(Intent.ACTION_ATTACH_DATA);
            setWall.setDataAndType(wallUri, "image/*");
            setWall.putExtra("png", "image/*");
            wrActivity.get().startActivityForResult(
                    Intent.createChooser(setWall, context.getResources().getString(R.string.set_as)), 1);
        } else {
            dialog.dismiss();
            Snackbar snackbar = Snackbar.make(layout, context.getResources().getString(R.string.error),
                    Snackbar.LENGTH_SHORT);
            final int snackbarLight = ContextCompat.getColor(context, R.color.snackbar_light);
            final int snackbarDark = ContextCompat.getColor(context, R.color.snackbar_dark);
            ViewGroup snackbarView = (ViewGroup) snackbar.getView();
            snackbarView.setBackgroundColor(ThemeUtils.darkTheme ? snackbarDark : snackbarLight);
            snackbar.show();
            snackbar.setCallback(new Snackbar.Callback() {
                @Override
                public void onDismissed(Snackbar snackbar, int event) {
                    super.onDismissed(snackbar, event);
                    if (toHide1 != null && toHide2 != null) {
                        toHide1.setVisibility(View.VISIBLE);
                        toHide2.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
    }
}

From source file:br.com.bioscada.apps.biotracks.io.file.importer.ImportActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();/*from   ww  w. ja va2  s  . c o m*/
    importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
    trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
    if (trackFileFormat == null) {
        trackFileFormat = TrackFileFormat.GPX;
    }

    if (!FileUtils.isExternalStorageAvailable()) {
        Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    String directoryPath;
    if (importAll) {
        directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension());
        directoryPath = FileUtils.getPath(trackFileFormat.getExtension());
        if (!FileUtils.isDirectory(new File(directoryPath))) {
            Toast.makeText(this, getString(R.string.import_no_directory, directoryDisplayName),
                    Toast.LENGTH_LONG).show();
            finish();
            return;
        }
    } else {
        String action = intent.getAction();
        if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
            Log.d(TAG, "Invalid action: " + intent);
            finish();
            return;
        }

        Uri data = intent.getData();
        if (!UriUtils.isFileUri(data)) {
            Log.d(TAG, "Invalid data: " + intent);
            finish();
            return;
        }
        directoryDisplayName = data.getPath();
        directoryPath = data.getPath();
    }

    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof ImportAsyncTask) {
        importAsyncTask = (ImportAsyncTask) retained;
        importAsyncTask.setActivity(this);
    } else {
        importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath);
        importAsyncTask.execute();
    }
}

From source file:com.github.snowdream.android.apps.imageviewer.ImageViewerActivity.java

public void doSettings() {
    if (!TextUtils.isEmpty(imageUri)) {
        Uri uri = Uri.parse(imageUri);//from ww w.j  a v  a 2 s .c o  m
        Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
        intent.setDataAndType(uri, "image/jpg");
        intent.putExtra("mimeType", "image/jpg");
        startActivityForResult(Intent.createChooser(intent, getText(R.string.action_settings)), 200);
    }
}

From source file:com.android.gallery3d.ui.MenuExecutor.java

public void onMenuClicked(int action, ProgressListener listener, boolean waitOnStop, boolean showDialog) {
    int title;//from w  w  w.  ja  v  a 2  s.co m
    switch (action) {
    case R.id.action_select_all:
        if (mSelectionManager.inSelectAllMode()) {
            mSelectionManager.deSelectAll();
        } else {
            mSelectionManager.selectAll();
        }
        return;
    case R.id.action_crop: {
        Intent intent = getIntentBySingleSelectedPath(CropActivity.CROP_ACTION);
        ((Activity) mActivity).startActivity(intent);
        return;
    }
    case R.id.action_edit: {
        Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_EDIT)
                .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        ((Activity) mActivity).startActivity(Intent.createChooser(intent, null));
        return;
    }
    case R.id.action_setas: {
        Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_ATTACH_DATA)
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("mimeType", intent.getType());
        Activity activity = mActivity;
        activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.set_as)));
        return;
    }
    case R.id.action_delete:
        title = R.string.delete;
        break;
    case R.id.action_rotate_cw:
        title = R.string.rotate_right;
        break;
    case R.id.action_rotate_ccw:
        title = R.string.rotate_left;
        break;
    case R.id.action_show_on_map:
        title = R.string.show_on_map;
        break;
    default:
        return;
    }
    startAction(action, title, listener, waitOnStop, showDialog);
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

private void setImageAsWallpaperPicker(Uri fileUri) {
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setType("image/*");

    MimeTypeMap map = MimeTypeMap.getSingleton();
    String mimeType = map.getMimeTypeFromExtension("png");
    intent.setDataAndType(fileUri, mimeType);
    intent.putExtra("mimeType", mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    startActivity(Intent.createChooser(intent, getString(R.string.action_set_as)));
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

private void setImageAsWallpaperPicker(Uri path) {
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setType("image/*");

    MimeTypeMap map = MimeTypeMap.getSingleton();
    String mimeType = map.getMimeTypeFromExtension("png");
    intent.setDataAndType(path, mimeType);
    intent.putExtra("mimeType", mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    startActivity(Intent.createChooser(intent, getString(R.string.action_set_as)));
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void setAsWallpaperMore() {

    String path = Environment.getExternalStorageDirectory().toString();
    File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png");
    Uri uri = Uri.fromFile(file);//  w w w  .  j av a2s .c o  m
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/png");
    intent.putExtra("mimeType", "image/png");
    startActivity(Intent.createChooser(intent, "Set as : Mood Wallpaper"));

    //        WallpaperManager myWallpaperManager
    //                = WallpaperManager.getInstance(getApplicationContext());
    //        try {
    //            myWallpaperManager.setBitmap(((BitmapDrawable) imageView.getDrawable()).getBitmap());
    //        } catch (IOException e) {
    //            // TODO Auto-generated catch block
    //            e.printStackTrace();
    //        }
}