open Image via mimetype using Intent - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

open Image via mimetype using Intent

Demo Code

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.MimeTypeMap;

public class Main{

    public static void openImage(Context context, Uri uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        String type = "image/*";

        String extension = MimeTypeMap.getFileExtensionFromUrl(uri
                .toString());//w  w  w. j a va  2s  . co  m
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
                extension);

        intent.setDataAndType(uri, type);

        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
    }

}

Related Tutorials