【问题标题】:Sending an sms intent to the Messaging app向消息应用程序发送短信意图
【发布时间】:2017-03-23 11:43:42
【问题描述】:

我的应用程序的目标是根据一些参数过滤接收到的SMS's,并根据这些参数的有效性来丢弃或接受SMS

我意识到不再可能(因为Android KitKat)有一个隐形应用程序可以做到这一点,因此我决定将其设为默认应用程序。

我目前在向股票SMS 应用程序发送意图(通过我的应用程序中的onReceive 函数,通过BroadcastReceiver 接收)时遇到很多麻烦(这将只允许某些SMS 到收到)。

我发现使用这段代码:

Telephony.Sms.getDefaultSmsPackage(getApplicationContext());

我能够为股票 SMS 应用程序获得使用过的打包 (com.android.mms)。通过一些研究,我发现transaction.SmsReceiver 是我正在寻找的课程。

但是,我现在无法将意图发送到此特定应用。

Intent redirectIntent = intent;
redirectIntent.setClassName("com.android.mms.transaction","com.android.mms.transaction.SmsReceiver");
redirectIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(redirectIntent);

我收到以下错误:

W/System.err: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.mms.transaction/com.android.mms.transaction.SmsReceiver}; 

【问题讨论】:

  • 首先,您不要使用startActivity()BroadcastReceiver 发送广播。其次,你不能做你想做的事。如果你是默认的,你处理一切。你不能只是传递你不想编码的函数。
  • @MikeM。那么有没有办法绕过这个呢?最终,我唯一想做的就是充当从某些号码派生的 SMS 的保险库,因此我不能让它们到达正常的收件箱。
  • 不。自从 KitKat 以来,真的没有任何像专门的 SMS 拦截器这样的东西了。只有默认可以阻止,但如果你是默认的,你要负责很多事情,包括发送和接收 SMS 和 MMS,处理它们在 Provider 中的存储等。

标签: java android android-intent sms smsmanager


【解决方案1】:

这可能对你有帮助

Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);

【讨论】:

    猜你喜欢
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多