阻止Android中发送SMS / MMS [英] Blocking outgoing SMS/MMS in android

查看:176
本文介绍了阻止Android中发送SMS / MMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了来电短信内容和收件箱进入前阻止相同。在code为如下:

I have Read Incoming SMS Content and Blocked the same before entering in to the inbox. The code is Given below:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class BroadCastReceiver extends BroadcastReceiver 
{
    /** Called when the activity is first created. */
    private static final String ACTION = "android.provider.Telephony.SEND_SMS";
    public static int MSG_TPE=0;
    public void onReceive(Context context, Intent intent) 
    { 
        String MSG_TYPE=intent.getAction();
            if(MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED"))
        {
//          Toast toast = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
//          toast.show();

        Bundle bundle = intent.getExtras();
        Object messages[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[messages.length];
        for (int n = 0; n < messages.length; n++) 
        {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        }

        // show first message
        Toast toast = Toast.makeText(context,"BLOCKED Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
        toast.show();
            abortBroadcast();
            for(int i=0;i<8;i++)
            {
                System.out.println("Blocking SMS **********************");
            }

        }
        else if(MSG_TYPE.equals("android.provider.Telephony.SEND_SMS"))
        {
            Toast toast = Toast.makeText(context,"SMS SENT: "+MSG_TYPE , Toast.LENGTH_LONG);
            toast.show();
            abortBroadcast();
            for(int i=0;i<8;i++)
            {
                System.out.println("Blocking SMS **********************");
            }

        }
        else
        {

            Toast toast = Toast.makeText(context,"SIN ELSE: "+MSG_TYPE , Toast.LENGTH_LONG);
            toast.show();
            abortBroadcast();
            for(int i=0;i<8;i++)
            {
                System.out.println("Blocking SMS **********************");
            }

        }

    }

}

在code正常工作的来电短信。显示在面包和块短信PDU的短信进入到收件箱。 但我的问题是一样的code不工作拨出短信。它不阻止即将离任的短信。我已经注册的BroadcastReceiver在AndroidManifest如下:

The code works fine on Incoming SMS. Shows the Sms pdu on Toast and blocks the SMS to enter in to Inbox. But my problem is that same Code is not working for Outgoing SMS. It doesnt blocks the Outgoing SMS. I have registered BroadcastReceiver in the AndroidManifest as follows.

<service  android:name=".MyService"    android:enabled="true"/>
         <receiver android:name="BroadCastReceiver">
                <intent-filter  android:priority="2147483647">
                    <action   android:name="android.provider.Telephony.SMS_SENT"/>
                </intent-filter>
         </receiver>
    <service  android:name=".MyServiceSentReceived"    android:enabled="true"/>
             <receiver android:name="BroadCastReceiver">
                    <intent-filter  android:priority="2147483645">
                        <action   android:name="android.provider.Telephony.SMS_RECEIVED"/>
                    </intent-filter>
             </receiver>
            <intent-filter>
                <action android:name="android.intent.action.SENDTO"></action>
                <data android:scheme="smsto"></data>
                <category android:name="android.intent.category.DEFAULT"></category>
            </intent-filter>

    and Permissions Like:
    <uses-permission android:name="android.permission.RECEIVE_SMS" />  
         <uses-permission android:name="android.permission.READ_SMS"/>
         <uses-permission android:name="android.permission.SEND_SMS"/>

任何人都可以请帮我到底哪里出问题了,为什么我不能够阻止传出的短信。谢谢

Can anyone please help me What is going wrong and why i am not able to block outgoing SMS. Thanks

推荐答案

您接收器时才会激活,当操作 android.provider.Telephony.SMS_RECEIVED 被激发。因此,它不反应,当短信被发送。

Your receiver is invoked only, when action android.provider.Telephony.SMS_RECEIVED is fired. Thus it doesn't react, when SMS is sent.

我远远不是专家,但我想,有没有可能,阻止传出的消息。默认的短信应用程序使用 android.telephony.SmsManager 的方法 SendDataMessage()不发送任何广播。

I am far from being expert, but I think, there is no possibility, to block outgoing messages. The default SMS Application uses android.telephony.SmsManager's method SendDataMessage() that doesn't send any broadcast.

这篇关于阻止Android中发送SMS / MMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆