Android的短讯意图过滤器 [英] Android sms intent filter

查看:163
本文介绍了Android的短讯意图过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这code在我的Andr​​oid应用程序的短信,但它不能正常工作,应用程序不会出现在邮件列表中。我应该补充一点,使其工作?

 <作用机器人:名称=android.intent.action.SENDTO/>
               <类机器人:名称=android.intent.category.DEFAULT/>
                <数据机器人:计划=短信/>
            <数据机器人:计划=smsto/>
                <数据机器人:MIMETYPE =text / plain的/>

          &所述; /意图滤光器>
 

解决方案

我提供你详细的说明做,在不同的情况下(与通讯录,文字股份等)。

清单条目为你的邮件活动

 <! - 还定义了应用程序的名称,在Android菜单 - >
    <活动
    机器人:名称=it.rainbowbreeze.smsforfree.ui.ActSendSms
    机器人:标签=@字符串/ common_appName
    >
    <! - 发送短信的人 - >
    <意向滤光器>
    <作用机器人:名称=android.intent.action.VIEW/>
    <作用机器人:名称=android.intent.action.SENDTO/>
    <类机器人:名称=android.intent.category.DEFAULT/>
    <类机器人:名称=android.intent.category.BROWSABLE/>
    <数据机器人:计划=短信/>
    <数据机器人:计划=smsto/>
    &所述; /意图滤光器>

    <! - 将文本发送给别人。这将使任何文字分享功能 - >
    <意向滤光器>
    <作用机器人:名称=android.intent.action.SEND/>
    <类机器人:名称=android.intent.category.DEFAULT/>
    <数据机器人:MIMETYPE =text / plain的/>
    &所述; /意图滤光器>
    < /活性GT;
 

现在我们已经取得了processIntentData方法如下所示的邮件活动被应用:

 私人无效processIntentData(意向意图)
{
    如果(空==意图)回报;

    如果(Intent.ACTION_SENDTO.equals(intent.getAction())){
        //数据我会找到目的地的数量
        串destionationNumber = intent.getDataString();
        destionationNumber = URLDe coder.de code(destionationNumber);
        //清除字符串
        destionationNumber = destionationNumber.replace( - ,)
            .replace(smsto:,)
            .replace(短信:,);
        //并设置领域
        mTxtDestination.setText(destionationNumber);

    }否则,如果(Intent.ACTION_SEND.equals(intent.getAction())及和放大器;text / plain的.equals(intent.getType())){
        //数据我会找到的消息的内容
        字符串消息= intent.getStringExtra(Intent.EXTRA_TEXT);
        //清除字符串
        mTxtBody.setText(消息);
    }
}
 

使用如图消息活动:

  @覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

    ...

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

    ...

    //执行的应用程序第一次运行时
    如果(空== savedInstanceState){
        processIntentData(getIntent());
    }
}
 

有关结果的附卡:

I tried this code in my android application for the SMS message but it is not working , the application does not appear in the messaging list. Should I add something to make it work?

             <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>

解决方案

I am providing you a detailed desc to do that in different case(with contacts, text shares etc).

Manifest Entry for you Message Activity

<!-- 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>

Now we have made a processIntentData method as shown below to be applied in 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);
    }
}

Use as shown in 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());
    }
}

The attached snap for results:

这篇关于Android的短讯意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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