本文整理匯總了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);
}