从图片uri中构造彩信pdu数据

适用于不经过消息界面,直接发送彩信图片的情况。

把媒体uri转换为byte数组。

 

在Mms中,写成某个类的一个静态函数,比如MessageUtils

 

public static byte[] getBytesFromUri(Uri mediaUri, Context context){ PduHeaders headers = new PduHeaders(); SendReq req = new SendReq(); String dests[] = {"123123"}; EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(dests); if (encodedNumbers != null) { req.setTo(encodedNumbers); } String subject = new String("subject"); if (null != subject) { req.setSubject(new EncodedStringValue(subject.toString())); } req.setDate(System.currentTimeMillis() / 1000L); try{ SlideshowModel slideshow = SlideshowModel.createNew(context); SlideModel slide = new SlideModel(slideshow); ImageModel media = new ImageModel(context, mediaUri, slideshow.getLayout().getImageRegion()); slideshow.add(slide); slideshow.get(0).add(media); PduBody pb = slideshow.toPduBody(); req.setBody(pb); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Priority. req.setPriority(PduHeaders.PRIORITY_NORMAL); // Delivery report. req.setDeliveryReport(PduHeaders.VALUE_NO); // Read report. req.setReadReport(PduHeaders.VALUE_NO); req.setMessageClass(PduHeaders.MESSAGE_CLASS_PERSONAL_STR.getBytes()); req.setDate(System.currentTimeMillis() / 1000L); }catch (MmsException e){ Log.d(TAG, "error"+e); } PduComposer compose = new PduComposer(context, req); return compose.make(); //return req; }

你可能感兴趣的:(从图片uri中构造彩信pdu数据)