1. 程式人生 > >android字串複製到剪貼簿

android字串複製到剪貼簿



android2.1之後版本 
其一:
(已執行成功 )

ClipboardManager clip = (ClipboardM anager)getSystemService(Context.CLIPB OARD_SERVICE); 

clip.getText();

// 貼上
clip.setText(str); 


// 複製其二:
ClipboardM anager c= (ClipboardManager)getSyste mService(CLIPBOARD_SERVICE); 
c.setTex t(smsContent.getText());
設定
Clipboard 的內容
c.getText(smsContent.getText()); 


提取clipboard的內容 

android2.1之前版 本
IClipboard clip = IClipboard.Stub.asIn terface(ServiceManager.getService("clip board")); 
clip.getClipboardText().toString ();
//獲得複製的內容 clip.setClipboardTex t(text);

//設定Clipboard 的內容

====================================================================

========================================================================

例子:複製;

		public void onClick(View arg0) {
			
//			拷貝功能
			ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); 
			clip.setText(Expression.number + "");
			
//			提示資訊
			Toast.makeText(MainActivity.this, "Copy Successful !", Toast.LENGTH_SHORT).show();
			show();
		}