通过ContentObserver检测输入和输出短消息是好的,还是使用BroadCast接收器接收到短信,ContentObserver用于发送短信?
发布于 2015-07-09 22:13:07
我有一个关于SMS和呼叫阻止程序的应用程序,但我从来没有上传它来玩商店,因为后Kitkat,你不能阻止短信。如果你想这么做,就别这样。我只是分享短信部分,你可以修改它,你想要的。
<!-- Android Permissions in manifest -->
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<!-- Define receiver inside the application tag -->
<receiver android:name="catchPackage.SmsController" android:process=":hascode_process" android:label="@string/sms_receiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<!-- Broadcast receiver java code -->
public void onReceive(Context context, Intent intent) {
this.context = context;
try{
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from = null;
String msg_body = null;
if (bundle != null){
try{
boolean delete= false;
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int k=0; k<msgs.length; k++){
msgs[k] = SmsMessage.createFromPdu((byte[])pdus[k]);
msg_from = msgs[k].getOriginatingAddress();
System.out.println(msg_from);
String msgBody = msgs[k].getMessageBody();
msg_body = msgBody;
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}https://stackoverflow.com/questions/31326771
复制相似问题