首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

彩信附件平添删除

2012-09-28 
彩信附件添加删除添加附件。在ComposeMessageActivity里addAttachment(int type) 函数根据type的不同,分成6

彩信附件添加删除
添加附件。

在ComposeMessageActivity里

addAttachment(int type) 函数

根据type的不同,分成6个case

case A:
MediaSelectListActivity.ADD_IMAGE 用gallery选图片:

MessageUtils.selectImage(this, REQUEST_CODE_ATTACH_IMAGE);

起一个intent:

   public static void resizeImageAsync(final Context context,            final Uri imageUri, final Handler handler,            final ResizeImageResultCallback cb, final boolean append) {        // Show a progress toast if the resize hasn't finished        // within one second.        // Stash the runnable for showing it away so we can cancel        // it later if the resize completes ahead of the deadline.        final Runnable showProgress = new Runnable() {            public void run() {                Toast.makeText(context, R.string.compressing,                        Toast.LENGTH_SHORT).show();            }        };        // Schedule it for one second from now.        handler.postDelayed(showProgress, 1000);        new Thread(new Runnable() {            public void run() {                final PduPart part;                try {                    UriImage image = new UriImage(context, imageUri);                    part = image.getResizedImageAsPart(MmsConfig                            .getMaxImageWidth(), MmsConfig.getMaxImageHeight(),                            MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD);                } finally {                    // Cancel pending show of the progress toast if necessary.                    handler.removeCallbacks(showProgress);                }                handler.post(new Runnable() {                    public void run() {                        cb.onResizeResult(part, append);                    }                });            }        }).start();    }


图片被缩放到最大640*480,如果还是大于300*1024-5000字节(差不多295k),那么缩放到295k。
这个大小是源码编写程序员凭感觉写死的。
这里的cb.onResizeResult是调用的ComposeMessageActivity的ResizeImageResultCallback里的函数。
处理大小结束后,会拿新的图片去再次setAttachment,
也就更新了附件。



热点排行