ورود

View Full Version : مشکل در خواندن clipboard



SZsXsZS
چهارشنبه 26 اسفند 1394, 17:11 عصر
این کدی هست که استفاده کردم:

ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if(clip!=null) {
ClipData.Item item = clip.getItemAt(0);
String text= item.getText().toString();
Log.d("log_tag", "clipboard: "+text);
}
else {
Log.d("log_tag", "clipboard empty");
}

مشکلش اینه که وقتی دستگاه ریستارت میشه، بعدش نمیتونه clipboard رو بخونه، و پیام clipboard empty میده، درحالیکه clipboard خالی نیست و توی برنامه های دیگه میشه محتویاتش رو Paste کرد! ولی وقتی یه متن جدیدی رو کپی کنم، اونوقت این کد بدون مشکل کار میکنه!!

قبلا در stackoverflow این مشکل رو مطرح کردم اما کسی جوابی نداد: http://stackoverflow.com/questions/35940003/why-this-read-clipboard-code-doesnt-work-immediatly-after-restart
ظاهرا این مشکل رو کس دیگری هم قبلا داشته: http://stackoverflow.com/questions/14252447/android-paste-text-from-clipboard-after-restarting-the-phone?rq=1

stackprogramer
چهارشنبه 26 اسفند 1394, 23:19 عصر
سلام یک پیشنهاد دارم،


// Gets a handle to the Clipboard Manager
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

// Checks to see if the clip item contains an Intent, by testing to see if getIntent() returns null
Intent pasteIntent = clipboard.getPrimaryClip().getItemAt(0).getIntent( );

if (pasteIntent != null) {

// handle the Intent

} else {

// ignore the clipboard, or issue an error if your application was expecting an Intent to be
// on the clipboard
}



از این سورس سایت اندروید دولپر استفاده کن،نتیجه چی میشه
http://developer.android.com/guide/topics/text/copy-paste.html

stackprogramer
پنج شنبه 27 اسفند 1394, 18:29 عصر
سلام ،راستی در مورد pending intent هم سرچ کن،که یک سرویس بسازی وقتی که اپت بسته هم باشد ،هر وقت کپی پیست باشد این سرویس ان را یک جا ذخیره می کنه وبرای استفاده بعد به کار برود.
PendingIntent is a special kind of Intent. It is an Intent that does not need your application to be active in order to perform some actions, you create an Intent and pass it to the system so that system does that work on your behalf as it was you doing that job! PendingIntent are like tokens, access keys, that you grant other applications or frameworks with, and they use them to mimic your application.