Get intent from Clipboard - Android android.content

Android examples for android.content:Clipboard

Description

Get intent from Clipboard

Demo Code

import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main{

    /**//from  www  .ja  v  a  2s . co  m
     * Get intent from Clipboard
     *
     * @param context
     * @return
     */
    public static Intent getIntent(Context context) {
        ClipboardManager clipboard = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboard.hasPrimaryClip()
                && clipboard.getPrimaryClipDescription().hasMimeType(
                        ClipDescription.MIMETYPE_TEXT_INTENT)) {
            ClipData clip = clipboard.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                return clip.getItemAt(0).getIntent();
            }
        }
        return null;
    }
}

Related Tutorials