移动到收件箱停止短信 [英] Stop SMS from moving to Inbox

查看:204
本文介绍了移动到收件箱停止短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 4.4系统之前,我是能够通过设置这样的优先级移动到收件箱中的邮件停止

Before Android 4.4 I was able to stop messages from moving to inbox by setting the priority like this

    <receiver android:name="com.serviceschedular.helperClasses.SmsReceiver" >
        <intent-filter android:priority="1000">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />          
        </intent-filter>
    </receiver>

然后abortBroadcast()的onRecieve()的消息。然而,在Android 4.4系统,我们需要以确定SMS_DELIVER_ACTION使我们的消息应用程序为默认值:

and then abortBroadcast() in onRecieve() messages. However in Android 4.4 we need to define SMS_DELIVER_ACTION in order to make our messaging app as default :

让你短信应用程序准备奇巧

这样一来,我可以先收到消息,他们不会移动到任何其他消息应用程序,但我还需要将它们发送到消息应用程序,如果它不填写我的标准。那么,有没有办法围绕实现这一功能?

By doing this I can receive messages first and they don't move to any other messaging app but I also need to send them to messaging app if it doesn't fill my criteria. So is there any way around to achieve this functionality?

推荐答案

当接收到Android系统的短信,它会广播一个有序的广播意图与行动android.provider.Telephony.SMS_RECEIVED。所有注册的接收器,包括系统默认的短信应用,收到此意图,以便放置在他们的意图过滤器的优先级。具有相同优先级广播receirers的顺序是不确定的。所有的BroadcastReceiver可以prevent接收使用abortBroadcast广播任何其他注册的广播接收器()。

When SMS is received by the Android system, it broadcasts an ordered broadcast Intent with action "android.provider.Telephony.SMS_RECEIVED". All registered receivers, including the system default SMS application, receive this Intent in order of priority that was set in their intent-filter. The order for broadcast receirers with the same priority is unspecified. Any BroadcastReceiver could prevent any other registered broadcast receivers from receiving the broadcast using abortBroadcast().

所以,这样你需要的一切是广播接收器:

So, everything you need is broadcast receiver like this:

public class SmsFilter extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                Object[] pdus = (Object[])extras.get("pdus");

                if (pdus.length < 1) return; // Invalid SMS. Not sure that it's possible.

                StringBuilder sb = new StringBuilder();
                String sender = null;
                for (int i = 0; i < pdus.length; i++) {
                    SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    if (sender == null) sender = message.getOriginatingAddress();
                    String text = message.getMessageBody();
                    if (text != null) sb.append(text);
                }
                if (sender != null && sender.equals("999999999")) {
                    // Process our sms...
                    abortBroadcast();
                }
                return;
            }
        }

        // ...
    }
}

貌似系统默认的短信处理应用程序使用的0优先级,所以你可以尝试1对您的应用程序是它之前。这些行添加到您的

Looks like the system default SMS processing application uses priority of 0, so you could try 1 for your application to be before it. Add these lines to your

AndroidManifest.xml中:

AndroidManifest.xml:

<receiver android:name=".SmsFilter">
    <intent-filter android:priority="1">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

不要忘了必要的权限:

Don't forget about necessary permissions:

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

顺便说一句,你可以找到所有已注册的接收器,并使用该code优先级:

By the way, you can find all registered receivers and their priorities using this code:

Intent smsRecvIntent = new Intent("android.provider.Telephony.SMS_RECEIVED");
List<ResolveInfo> infos = context.getPackageManager().queryBroadcastReceivers(smsRecvIntent, 0);
for (ResolveInfo info : infos) {
    System.out.println("Receiver: " + info.activityInfo.name + ", priority=" + info.priority);
      }

=============================================== ==================

=================================================================

有关prevent短信会在Android的奇巧到收件箱

For prevent SMS going to inbox in Android Kitkat

一个变化是奇巧,只允许一个应用程序的时间(默认短信应用程序)来对短信写权限数据库,并能使用它介绍。

A change was introduced in KitKat that only allows one application at a time (the default SMS app) to have write permissions on the SMS DB and to be able to consume it.

您有2种方式解决你的问题的:

You have 2 ways of solving your problem:

  • 按照有关如何申请用户时,当您需要执行更改(时间默认短信应用程序切换到您的应用程序谷歌的意见,一旦你完成这样做,允许用户切换回原来的默认短信应用程序)。
  • 找到一个临时哈克的方式做你需要做的。作为一个暗示,有一个隐藏的API:    AppOpsManager ,你可能为了给您的应用程序写入的权限漏洞( OP_WRITE_SMS),头部到这个XDA页面,了解更多关于它:
  • Follow Google advice on how to request the user to switch the default SMS application to your application during the time when you need to perform your changes (and once you finish doing it, allow the user to switch back to the original default SMS app).
  • Find a temporary hacky way to do what you need to do. As a hint, there is a hidden API: AppOpsManager that you could potentially exploit in order to give your application write permissions (OP_WRITE_SMS), head over to this XDA page to learn more about it:

如何写入短信内容提供商的Andr​​oid奇巧没有被默认的SMS应用程序

回复,如果您有任何疑问...

Reply if you have any query...

更新

这机器人4.4奇巧开始,它是不能够进行任何种类的SMS相关的操作而不被默认的SMS应用程序。还原和备份应用程序不能做到这一点无论是。他们中的大多数已经更新他们的应用程序,以支持此功能,现在要求用户选择它们作为默认的短信应用程序。

Starting from Android 4.4 Kitkat, it is not possible to perform any kind of SMS related operations without being the default SMS app. Restore and Backup apps cannot do it either. Most of them have updated their app to support this functionality and now ask the user to select them as the default SMS app.

Android的奇巧更新停止支持编写短信与其他应用程序。你只能听,不能写入。如果你想发送短信,你必须将其发送到默认的SMS意图,用户必须同意并点击发送短信之前先发送。

Android KitKat update stopped supporting writing the SMS with other apps. You can only listen but cannot write. If you want to send sms, you have to send it to default SMS intent and the user has to approve and click SEND before sending SMS.

有关您参考: SMS提供

这篇关于移动到收件箱停止短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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