短信猫的实现

接收短信部分,将短信猫设置成系统短信后即可,使用过小米、三星验证ok,附带github代码

1.Androidmanifest.xml

<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".activity.ComposeSmsActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <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" />
        <data android:scheme="mms" />
        <data android:scheme="mmsto" />
    </intent-filter>
</activity>

<!-- Services -->
<service android:name="com.yjf.smsmall.service.SmsReceiverService"/>

<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver android:name="com.yjf.smsmall.receiver.MmsReceiver"
    android:permission="android.permission.BROADCAST_WAP_PUSH">
    <intent-filter>
        <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
        <data android:mimeType="application/vnd.wap.mms-message" />
    </intent-filter>
</receiver>

<!-- Receiver for pre kitkat. This is disabled when it's kitkat and above -->
<receiver
    android:name="com.yjf.smsmall.receiver.SmsReceiver"
    android:permission="android.permission.BROADCAST_SMS"
    android:enabled="true"   
    >
    <intent-filter >
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        <action android:name="android.provider.Telephony.SMS_DELIVER"/>
    </intent-filter>
</receiver>
<!--enabled必须设置为true,否则收不到短信-->
<service
    android:name="com.yjf.smsmall.service.HeadlessSmsSendService"
    android:exported="true"
    android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
    <intent-filter>
        <action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
        <category android:name="android.intent.category.DEFAULT"/>

        <data android:scheme="sms"/>
        <data android:scheme="smsto"/>
        <data android:scheme="mms"/>
        <data android:scheme="mmsto"/>
    </intent-filter>
</service>
public class ComposeSmsActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

}
public class HeadlessSmsSendService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
public class MmsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    }
}
public class SmsReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        intent.setClass(context, SmsReceiverService.class);
        intent.putExtra("result", getResultCode());
        SmsReceiverService.beginStartingService(context, intent);
    }
}
MainActivity调用一下短信读取

public class MainActivity extends AppCompatActivity {

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

        Uri uriSms = Uri.parse("content://sms/inbox");
        uriSms = uriSms.buildUpon().appendQueryParameter("LIMIT", "10").build();
        String[] projection = {
                "_id", "address", "date", "body"
        };

        Cursor c = getContentResolver().query(uriSms, projection, null,
                null, "date DESC");

    }

}

SmsReceiverService 服务里获取并处理接收到的短信

github:https://github.com/yujfei/SmsMall.git






















































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值