当前位置: 首页>>代码示例>>Java>>正文


Java ClipboardManager.addPrimaryClipChangedListener方法代码示例

本文整理汇总了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);
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:29,代码来源:CaptureActivity.java

示例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);
}
 
开发者ID:Team-Sprout,项目名称:Clipcon-AndroidClient,代码行数:9,代码来源:ClipboardService.java

示例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);
                }
            }
        });
    }
 
开发者ID:xiaofei-dev,项目名称:SuspendNotification,代码行数:31,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:Sea-n,项目名称:gitio,代码行数:14,代码来源:ClipboardService.java

示例5: onCreate

import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    mClipboardManager =
            (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    mClipboardManager.addPrimaryClipChangedListener(
            mOnPrimaryClipChangedListener);
}
 
开发者ID:bachors,项目名称:Insta-Downloader,代码行数:9,代码来源:ClipBoardService.java

示例6: onCreate

import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    handler=new Handler();
    manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    manager.addPrimaryClipChangedListener(listener);

}
 
开发者ID:zhaoweihaoChina,项目名称:MrTranslator,代码行数:10,代码来源:ClipboardService.java

示例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);
}
 
开发者ID:littleRich,项目名称:AutoInteraction-Library,代码行数:9,代码来源:QQSimulateBusiness.java

示例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);
}
 
开发者ID:vshkl,项目名称:SaveIg,代码行数:9,代码来源:ClipboardService.java

示例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());
                    }
                }
            }
        }
    });
}
 
开发者ID:EggUncle,项目名称:XposedNavigationBar,代码行数:30,代码来源:MyClipBoard.java

示例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();
		}
	});
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:12,代码来源:Clipboard.java

示例11: onCreate

import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
    pm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    pm.addPrimaryClipChangedListener(listener);
}
 
开发者ID:mmjang,项目名称:quiz_helper,代码行数:6,代码来源:CBWatcherService.java

示例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);
}
 
开发者ID:gaelthas,项目名称:Pindroid,代码行数:58,代码来源:ClipboardService.java

示例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);
}
 
开发者ID:Rishabhk07,项目名称:multi-copy,代码行数:44,代码来源:TextCaptureService.java


注:本文中的android.content.ClipboardManager.addPrimaryClipChangedListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。