1.獲取剪切版內(nèi)容
2.操作后清楚剪切板
3.在activity里面做某事
c = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
c.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
Log.d("aa", "后期分享用到這里");
}
});
this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override
public void onActivityStarted(Activity activity) {
}
@Override
public void onActivityResumed(Activity activity) {
if(c.getPrimaryClip()!=null&&c.getPrimaryClip().getItemCount()>0)
{
String s = c.getPrimaryClip().getItemAt(0).getText().toString();
Log.d("aa",s);
if(!TextUtils.isEmpty(s)&&s.contains(QianbaoCVUtils.SEPARATOR))
{
//處理之前清楚掉,剪切版,省的多事
c.setPrimaryClip( ClipData.newPlainText(s,""));
try {//do something
QianbaoCVUtils.checkUrlDoSomething(activity, s);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
});
}