本文整理汇总了Java中android.content.ClipboardManager.addPrimaryClipChangedListener方法的典型用法代码示例。如果您正苦于以下问题:Java ClipboardManager.addPrimaryClipChangedListener方法的具体用法?Java ClipboardManager.addPrimaryClipChangedListener怎么用?Java ClipboardManager.addPrimaryClipChangedListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ClipboardManager
的用法示例。
在下文中一共展示了ClipboardManager.addPrimaryClipChangedListener方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleText
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 解析成功的文本信息
*
* @param text
*/
private void handleText(String text) {
// 获取到扫描的到text信息,可以根据正则表达式判断进行哪种处理
/* 1. url -> (1) contains('scan_login') 使用okhttp GET request ; (2) contains('oschina.net') webView跳转
* 2. text -> (1) matches("^\\{.*")) 说明是Json格式, 解析json为JavaBean,根据JavaBean的类型调用okhttp处理请求如: 签到; (2) 复制普通文本
*/
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newPlainText("myLabel", text);
// 复制到剪切板
clipboardManager.setPrimaryClip(mClipData);
// 剪贴板的数据改变监听器
clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
System.out.println("======> 剪切板数据改变 <====== ");
}
});
// 移除指定的剪贴板数据改变监听器
// cbm.removePrimaryClipChangedListener(listener);
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
// 处理完之后, 要么finish Activity, 要么 handler.sendEmptyMessage(R.id.restart_preview);
restartPreviewAfterDelay(3000);
}
示例2: onStartCommand
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
mClipboardManager.addPrimaryClipChangedListener(changedListener);
return super.onStartCommand(intent, flags, startId);
}
示例3: clipBoardMonitor
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
*desc:此方法设置监听剪贴板变化,如有新的剪贴内容就启动主活动
*/
private void clipBoardMonitor(){
final ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
if(!isChecked){
return;
}else {
ClipData clipData = clipBoard.getPrimaryClip();
ClipData.Item item = clipData.getItemAt(0);
//String text = item.getText().toString();//万一复制到剪贴板的不是纯文本,此方法将导致程序崩溃
String text = item.coerceToText(MainActivity.this).toString();//
//下面的条件判断是为了防止与淘宝淘口令的冲突问题。
if(text.equals("")){
return;
}
Intent intent = new Intent(MainActivity.this,MyService.class);
intent.putExtra("TEXT",text);
MainActivity.this.startService(intent);
// Intent intent = newIntent(MainActivity.this,text);
// Log.d(TAG, "onPrimaryClipChanged: ");
// startActivity(intent);
}
}
});
}
示例4: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH)
return;
if (!getSharedPreferences("data", MODE_PRIVATE).getBoolean("read_clipboard", true))
return;
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboard != null) {
clipboard.addPrimaryClipChangedListener(listener);
}
}
示例5: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mClipboardManager =
(ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
mClipboardManager.addPrimaryClipChangedListener(
mOnPrimaryClipChangedListener);
}
示例6: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
handler=new Handler();
manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
manager.addPrimaryClipChangedListener(listener);
}
示例7: readyClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
private void readyClipboard(ClipboardManager.OnPrimaryClipChangedListener listener) {
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (null != mPrimaryClipChangedListener) {
clipboardManager.removePrimaryClipChangedListener(mPrimaryClipChangedListener);
}
mPrimaryClipChangedListener = listener;
clipboardManager.addPrimaryClipChangedListener(mPrimaryClipChangedListener);
}
示例8: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
clipboardManager.addPrimaryClipChangedListener(this);
NotificationHelper.showNotification(this);
}
示例9: startListenClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 开始监听剪贴板
*/
public static void startListenClipboard(final Context context) {
final ClipboardManager clipboard = (ClipboardManager) context.
getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
// XpLog.i("onPrimaryClipChanged");
//获取剪贴板内容,先判断该内容是否为空
if (clipboard.hasPrimaryClip()) {
ClipData clipData = clipboard.getPrimaryClip();
int count = clipData.getItemCount();
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
CharSequence str = item
.coerceToText(context);
//因为复制历史记录里面某一条文字到剪贴板的时候,也会导致剪贴板内容变动,此处避免 添加重复内容到剪贴板历史
if (!clipboardData.contains(str.toString())) {
clipboardData.add(str.toString());
}
}
}
}
});
}
示例10: setListener
import android.content.ClipboardManager; //导入方法依赖的package包/类
public void setListener(final Context context, final Runnable listener)
{
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
clipboard.addPrimaryClipChangedListener(new OnPrimaryClipChangedListener()
{
public void onPrimaryClipChanged()
{
listener.run();
}
});
}
示例11: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
pm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
pm.addPrimaryClipChangedListener(listener);
}
示例12: onCreate
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL,
getString(R.string.app_name), NotificationManager.IMPORTANCE_LOW);
channel.setLightColor(Color.BLUE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
mNotificationManager.createNotificationChannel(channel);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
mBuilder = new Notification.Builder(getApplicationContext(), DEFAULT_CHANNEL);
} else {
mBuilder = new Notification.Builder(getApplicationContext());
}
Intent intentNotify = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intentNotify, 0);
List<BaseItem> baseItems = ItemUtils.getAllItem(this);
String content = "";
if (baseItems != null && baseItems.size() > 0) {
content = baseItems.get(0).getContent();
} else {
content = "";
}
mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (mClipboardManager != null) {
ClipData clipData = mClipboardManager.getPrimaryClip();
int count = clipData.getItemCount();
String currentContent = "";
if (count > 0) {
currentContent = clipData.getItemAt(count - 1).getText().toString();
}
if (!currentContent.equals(content)) {
if (ItemUtils.addItem(getApplicationContext(), new BaseItem("", currentContent))) {
content = currentContent;
PindroidApplication.getINSTANCE().refreshItem();
}
}
mBuilder
.setContentTitle("title")
.setContentText(content)
.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentIntent(pendingIntent)
;
mClipboardManager.addPrimaryClipChangedListener(mClipListener);
mNotification = mBuilder.build();
startForeground(NOTIFICATION_ID, mNotification);
}
PindroidApplication.getINSTANCE().setServiceListener(mOnDataChangeListener);
}
示例13: onStartCommand
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (textCapture_LOG)
Log.d(TAG, "onStartCommand: ");
toggleService = true;
final ArrayList<String> copiedDataArray = new ArrayList<>();
clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
if (textCapture_LOG)
Log.d(TAG, "onPrimaryClipChanged: before changing");
if(toggleService) {
if (textCapture_LOG)
Log.d(TAG, "onPrimaryClipChanged: ");
final ClipData clipData = clipboardManager.getPrimaryClip();
if (clipData.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
|| clipData.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)
|| clipData.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
ClipData.Item item = clipData.getItemAt(0);
String thisText = item.getText().toString();
String sb = "";
copiedDataArray.add(thisText);
for (String text : copiedDataArray) {
sb += text + "\n";
}
ClipData copiedClip = ClipData.newPlainText("copiedClip", sb);
clipboardManager.removePrimaryClipChangedListener(this);
clipboardManager.setPrimaryClip(copiedClip);
clipboardManager.addPrimaryClipChangedListener(this);
Toast.makeText(TextCaptureService.this, "Multi Copied", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(TextCaptureService.this, "only text is allowed", Toast.LENGTH_SHORT).show();
}
}
});
return super.onStartCommand(intent, flags, startId);
}