本文介绍了如何将某些特定的SMS内容复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与我合作的银行每当我要输入以检查我的帐户时,都会向我发送一条包含随机生成的六位数代码的SMS。而且每次手动键入它真的很累。我正在考虑制作一个小应用程序,以便将该六位数的数字复制到剪贴板中,以便在SMS到达时立即将其粘贴到相关字段中。
The bank that I'm working with sends me an SMS containing a random generated six digit code whenever I want to enter for checking my accounts. And everytime it is really tiring to type it manually. I'm thinking about making a little application in order to copy that six digit number into the clipboard so that I paste it instantly to the related field whenever an SMS arrives. Could you please share your ideas on this subject with me?
谢谢,
YB
Thanks,YB
推荐答案
public class SmsListener extends BroadcastReceiver{
private SharedPreferences preferences;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
// VALIDATE msgBody WITH SOME CONTENT YOU NEED...
// if(VALIDATED)
// COPY msgBody TO CLIPBOARD
}
}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
}
}
注意:在清单文件中,添加BroadcastReceiver-
Note: In your manifest file add the BroadcastReceiver-
<receiver android:name=".listener.SmsListener">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
添加此权限:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
将文本复制到剪贴板使用以下链接
这篇关于如何将某些特定的SMS内容复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!