Created
December 2, 2015 23:06
-
-
Save mkonicek/37ab8d73e3d6102b8b03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.SuppressLint; | |
import android.content.ClipboardManager; | |
import android.content.ClipData; | |
import android.content.Context; | |
import android.os.Build; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.bridge.ReactContext; | |
import com.facebook.react.bridge.ReactContextBaseJavaModule; | |
import com.facebook.react.bridge.ReactMethod; | |
/** | |
* Pasteboard native module, allowing application to access native device clipboard. | |
*/ | |
public class PasteboardModule extends ReactContextBaseJavaModule { | |
public PasteboardModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
} | |
@Override | |
public String getName() { | |
return "Pasteboard"; | |
} | |
@SuppressLint("DeprecatedMethod") | |
@ReactMethod | |
public void setPasteboardString(String text) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
ClipData clipdata = ClipData.newPlainText(null, text); | |
ClipboardManager clipboard = | |
(ClipboardManager) getReactApplicationContext() | |
.getSystemService(Context.CLIPBOARD_SERVICE); | |
clipboard.setPrimaryClip(clipdata); | |
} else { | |
ClipboardManager textClipboard = | |
(ClipboardManager) getReactApplicationContext() | |
.getSystemService(Context.CLIPBOARD_SERVICE); | |
textClipboard.setText(text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment