草庐IT

Android 短信 Intent 过滤器

coder 2023-12-09 原文

我在我的 android 应用程序中尝试了这段代码来获取 SMS 消息,但它不起作用,该应用程序没有出现在消息列表中。我应该添加一些东西来让它工作吗?

             <action android:name="android.intent.action.SENDTO" />
               <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="sms" />
            <data android:scheme="smsto" />
                <data android:mimeType="text/plain" />

          </intent-filter>

最佳答案

我正在为您提供在不同情况下执行此操作的详细说明(包括联系人、文本共享等)。

消息 Activity 的 list 条目

<!-- Defines also the app name in the Android menu -->
    <activity
    android:name="it.rainbowbreeze.smsforfree.ui.ActSendSms"
    android:label="@string/common_appName"
    >
    <!-- Sends sms for someone  -->
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.SENDTO" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="sms" />
    <data android:scheme="smsto" />
    </intent-filter>

    <!-- Sends text to someone .This will enable any Text Share functionality-->
    <intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
    </intent-filter>
    </activity>

现在我们已经制作了一个processIntentData方法,如下所示,应用在Message Activity中:

private void processIntentData(Intent intent)
{
    if (null == intent) return;

    if (Intent.ACTION_SENDTO.equals(intent.getAction())) {
        //in the data i'll find the number of the destination
        String destionationNumber = intent.getDataString();
        destionationNumber = URLDecoder.decode(destionationNumber);
        //clear the string
        destionationNumber = destionationNumber.replace("-", "")
            .replace("smsto:", "")
            .replace("sms:", "");
        //and set fields
        mTxtDestination.setText(destionationNumber);

    } else if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
        //in the data i'll find the content of the message
        String message = intent.getStringExtra(Intent.EXTRA_TEXT);
        //clear the string
        mTxtBody.setText(message);
    }
}

如消息 Activity 所示使用:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    mTxtDestination = (EditText) findViewById(R.id.actsendsms_txtDestination);
    mTxtBody = (EditText) findViewById(R.id.actsendsms_txtMessage);

    ...

    //executed when the application first runs
    if (null == savedInstanceState) {
        processIntentData(getIntent());
    }
}

随附的结果截图:

关于Android 短信 Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847876/

有关Android 短信 Intent 过滤器的更多相关文章

  1. ruby-on-rails - 事件管理员日期过滤器日期格式自定义 - 2

    是否有简单的方法来更改默认ISO格式(yyyy-mm-dd)的ActiveAdmin日期过滤器显示格式? 最佳答案 您可以像这样为日期选择器提供额外的选项,而不是覆盖js:=f.input:my_date,as::datepicker,datepicker_options:{dateFormat:"mm/dd/yy"} 关于ruby-on-rails-事件管理员日期过滤器日期格式自定义,我们在StackOverflow上找到一个类似的问题: https://s

  2. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  3. ruby-on-rails - 在 Controller 中干净地处理多个过滤器(参数) - 2

    我有一个名为Post的类,我需要能够适应以下场景:如果用户选择了一个类别,则只显示该类别的帖子如果用户选择了一种类型,则只显示该类型的帖子如果用户选择了一个类别和类型,则只显示该类别中该类型的帖子如果用户没有选择任何内容,则显示所有帖子我想知道我的Controller是否不可避免地会因大量条件语句而显得粗糙...这是我解决此问题的错误方法-有谁知道我如何才能做到这一点?classPostsController 最佳答案 您最好遵循“胖模型,瘦Controller”的惯例,这意味着您应该将这种逻辑放在模型本身中。Post类应该能够报告

  4. ruby-on-rails - 如何处理 Grape 中特定操作的过滤器之前? - 2

    我正在我的Rails项目中安装Grape以构建RESTfulAPI。现在一些端点的操作需要身份验证,而另一些则不需要身份验证。例如,我有users端点,看起来像这样:moduleBackendmoduleV1classUsers现在如您所见,除了password/forget之外的所有操作都需要用户登录/验证。创建一个新的端点也没有意义,比如passwords并且只是删除password/forget从逻辑上讲,这个端点应该与用户资源。问题是Grapebefore过滤器没有像except,only这样的选项,我可以在其中说对某些操作应用过滤器。您通常如何干净利落地处理这种情况?

  5. ruby-on-rails - Rails 3 - 过滤器链暂停为 :authentication rendered or redirected - 2

    我仍然收到标题中的“错误”消息,但不知道如何解决。在ApplicationController中,classApplicationController在routes.rb#match'set_activity_account/:id/:value'=>'users#account_activity',:as=>:set_activity_account--thisdoesn'tworkaswell..resources:usersdomemberdoget:action_a,:action_bendcollectiondoget'account_activity'endend和User

  6. ruby-on-rails - ActiveAdmin 自定义选择过滤器下拉名称 - 2

    对于用户模型,我有一个过滤器来检查用户的预订状态,该状态由整数值(0、1或2)表示。UserActiveAdmin索引页上的过滤器是通过以下代码实现的:filter:booking_status,as::select然而,这会导致下拉选项为0、1或2。当管理员用户从下拉列表中选择它们时,我更愿意自己将它们命名为“未完成”、“待定”和“已确认”之类的名称。有没有办法在不改变booking_status在模型中的表示方式的情况下做到这一点? 最佳答案 假设booking_status是模型中的枚举字段,您可以使用:过滤器:booking

  7. ruby - 如何通过 belongs_to 按外部 id 和本地属性进行过滤? - 2

    以下模型通过belongs_to链接:require'mongoid'classSensorincludeMongoid::Documentfield:sensor_id,type:Stringvalidates_uniqueness_of:sensor_idend...require'mongoid'require_relative'sensor.rb'classSensorDataincludeMongoid::Documentbelongs_to:sensorfield:date,type:Datefield:ozonMax1h,type:Floatfield:ozonMax8h

  8. ruby - Rails+ActiveAdmin - 使用 ransacker 过滤会抛出错误 PG::SyntaxError: ERROR: syntax error at or near "," - 2

    我在RubyonRails4.1.4上有一个项目,使用来自git://github.com/activeadmin/activeadmin的activeadmin1.0.0.pre,pg0.17.1,PostgreSQL9.3在项目中我有这些模型:类用户has_one:账户类账户属于:用户有很多:project_accountshas_many:项目,:through=>:project_accounts类项目#该项目有一个bool属性'archive'has_many:project_accounts类ProjectAccount属于:帐户属于:项目我有一个任务是在索引页面上实现一个

  9. ruby-on-rails - Rails 中的协同过滤 - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我正在寻找一种在Rails中进行协作过滤的解决方案,甚至是可能的示例。到目前为止,我只发现了acts_as_recommendable,它看起来很有用,但我注意到它在过去2年中没有任何更新。有人知道任何其他解决方案和/或示例吗?

  10. ruby - 在 Jekyll 中过滤 site.related_posts - 2

    我对Jekyll和Ruby很陌生(但是,非常兴奋)。在不使用插件的情况下,我试图找到一种方法来过滤site.related_posts。例如,我正在阅读标题为Foo且类别为A、B的帖子。该站点总共包含3个帖子:Foo(类别:A、B)条形图(类别:A、C、D)动物园(类别:B、F)默认情况下,在Jekyll中我们这样做:{%forpostinsite.related_postslimit:5%}{%endfor%}但是,上面的代码返回所有(3)个帖子。一个帖子包含很多类别,所以类别应该是一个数组。如何修改代码并仅返回类别与当前帖子类别相交的类别?(在此示例中,我希望代码仅返回Foo和Zo

随机推荐