是否有可能阻止传出短信? [英] Is it possible to block Outgoing SMS?

查看:98
本文介绍了是否有可能阻止传出短信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我使用的code,

 公共类MyCallControllerActivity扩展活动
{
    静态诠释计数;
 / **第一次创建活动时调用。 * /
 复选框blockAll_cb; //,blockcontacts_cb;
 BroadcastReceiver的CallBlocker;

 TelephonyManager telephonyManager;


@覆盖
 公共无效的onCreate(包savedInstanceState)
{
 super.onCreate(savedInstanceState);
 的setContentView(R.layout.activity_main);
 initviews();

 CallBlocker =新的BroadcastReceiver()
 {


@覆盖
 公共无效的onReceive(上下文的背景下,意图意图)
 {
     捆绑包= intent.getExtras();
     //束束= intent.getExtras();


        如果(捆绑!= NULL)
        {
           //你的操作上串,如果你能中止。


        }

        对象信息[] =(对象[])bundle.get(的PDU);
        SmsMessage smsMessage [] =新SmsMessage [messages.length]

        对于(INT N = 0; N< messages.length; N ++)
        {
        smsMessage [η] = SmsMessage.createFromPdu((字节[])消息[n])的;
        }
        如果(+ 919739036754.equalsIgnoreCase(smsMessage [0] .getOriginatingAddress()))
        {
            // abortBroadcast();
            串车身= smsMessage [0] .getMessageBody();
            如果(Body.startsWith(START))
            {
                吐司toast6 = Toast.makeText(背景下,有START,Toast.LENGTH_LONG); toast6.show();

            }
            其他
            {
                setResultData(空);
                的setResult code(0);
                abortBroadcast();
            }
        }
        其他
        {


        }
        //显示第一条消息
        吐司toast1 = Toast.makeText(背景下,发来的短信:+ smsMessage [0] .getOriginatingAddress()+\ nBody:+ smsMessage [0] .getMessageBody(),Toast.LENGTH_LONG);
        toast1.show();

 }
 }; // BroadcastReceiver的
 IntentFilter的过滤器=新的IntentFilter(android.provider.Telephony.SMS_SENT);
 registerReceiver(CallBlocker,过滤器);




}



 公共无效initviews()
 {
 blockAll_cb =(复选框)findViewById(R.id.cbBlockAll);

 }
 @覆盖
 保护无效的onDestroy(){
 // TODO自动生成方法存根
 super.onDestroy();
 如果(CallBlocker!= NULL)
 {
 unregisterReceiver(CallBlocker);
 CallBlocker = NULL;
 }
 

下面是清单,

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.block
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =17/>
     <使用-权限的Andr​​oid:名称=android.permission.CALL_PHONE/>
    <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.PROCESS_OUTGOING_CALLS/>
    <使用特征的android:NAME =android.hardware.telephony/>
    <使用-权限的Andr​​oid:名称=android.permission.READ_SMS/>
    <使用-权限的Andr​​oid:名称=android.permission.WRITE_SMS/>
    <使用-权限的Andr​​oid:名称=android.permission.SEND_SMS/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_SMS/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_MMS/>

    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名称=com.example.block.MyCallControllerActivity
            机器人:标签=@字符串/ APP_NAME>
            <意图过滤器的Andr​​oid版本:优先=1000>
                <作用机器人:名称=android.intent.action.MAIN/>
                <作用机器人:名称=android.provider.Telephony.SMS_RECEIVED/>
                <作用机器人:名称=android.provider.Telephony.SMS_SENT/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>

< /舱单>
 

解决方案

您不能阻止默认的邮件应用程序传出的短信,因为没有播出外发短信。

一个简单的谷歌搜索,就会发现这一点。 https://www.google.com/search?q=block +传出+短信+安卓+编程

Here is the Code which I am using,

public class MyCallControllerActivity extends Activity 
{
    static int Count;
 /** Called when the activity is first created. */
 CheckBox blockAll_cb;//,blockcontacts_cb;
 BroadcastReceiver CallBlocker;

 TelephonyManager telephonyManager;


@Override
 public void onCreate(Bundle savedInstanceState) 
{
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 initviews();

 CallBlocker =new BroadcastReceiver()
 {


@Override
 public void onReceive(Context context, Intent intent) 
 {
     Bundle bundle = intent.getExtras();
     //Bundle bundle = intent.getExtras();


        if ( bundle != null )
        {
           // do you manipulation on String then if you can abort.


        }

        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]);
        }
        if("+919739036754".equalsIgnoreCase(smsMessage[0].getOriginatingAddress()))
        {
            //abortBroadcast();
            String Body=smsMessage[0].getMessageBody();
            if (Body.startsWith("START"))
            {
                Toast toast6 = Toast.makeText(context,"There is START ", Toast.LENGTH_LONG);toast6.show(); 

            }
            else
            {
                setResultData(null);
                setResultCode(0);
                abortBroadcast();
            }
        }
        else
        {


        }
        // show first message
        Toast toast1= Toast.makeText(context,"Sent SMS: " + smsMessage[0].getOriginatingAddress()+ "\nBody: "+smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
        toast1.show(); 

 }
 };//BroadcastReceiver
 IntentFilter filter= new IntentFilter("android.provider.Telephony.SMS_SENT");
 registerReceiver(CallBlocker, filter);




}



 public void initviews()
 {
 blockAll_cb=(CheckBox)findViewById(R.id.cbBlockAll);

 }
 @Override
 protected void onDestroy() {
 // TODO Auto-generated method stub
 super.onDestroy();
 if (CallBlocker != null)
 {
 unregisterReceiver(CallBlocker);
 CallBlocker = null;
 }

Here is the Manifest,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.block"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
     <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-feature android:name="android.hardware.telephony" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.block.MyCallControllerActivity"
            android:label="@string/app_name" >
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
                <action android:name="android.provider.Telephony.SMS_SENT" />                   
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

解决方案

You cannot block the Outgoing SMS from the default Message application because there is no Broadcast for Outgoing Text Messages.

A Simple Google search will reveal this. https://www.google.com/search?q=block+outgoing+sms+android+programmatically

这篇关于是否有可能阻止传出短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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