[퍼미션]

<uses-permission android:name="android.permission.READ_CLIPBOARD" />
<uses-permission android:name="android.permission.WRITE_CLIPBOARD" />

 

/**
 * Todo : 클립보드 복사 (clipboard)
 */
@JavascriptInterface
public void clipboard(final String message) {
    DLog.i(new Exception(), message);
    try {
        JSONObject reqMessage = new JSONObject(message);
        String clipboardData = (String) reqMessage.get("clipboard");
        ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText("label", clipboardData);
        clipboardManager.setPrimaryClip(clipData);
    }
    catch (JSONException e) {
        Log.e("[clipboard Exception", e.getMessage());
    }
}

+ Recent posts