Search in sources :

Example 1 with EMFileMessageBody

use of com.hyphenate.chat.EMFileMessageBody in project SmartCampus by Vegen.

the class EaseShowNormalFileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ease_activity_show_file);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    final EMMessage message = getIntent().getParcelableExtra("msg");
    if (!(message.getBody() instanceof EMFileMessageBody)) {
        Toast.makeText(EaseShowNormalFileActivity.this, "Unsupported message body", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    final File file = new File(((EMFileMessageBody) message.getBody()).getLocalUrl());
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            runOnUiThread(new Runnable() {

                public void run() {
                    FileUtils.openFile(file, EaseShowNormalFileActivity.this);
                    finish();
                }
            });
        }

        @Override
        public void onError(int code, String error) {
            runOnUiThread(new Runnable() {

                public void run() {
                    if (file != null && file.exists() && file.isFile())
                        file.delete();
                    String str4 = getResources().getString(R.string.Failed_to_download_file);
                    Toast.makeText(EaseShowNormalFileActivity.this, str4 + message, Toast.LENGTH_SHORT).show();
                    finish();
                }
            });
        }

        @Override
        public void onProgress(final int progress, String status) {
            runOnUiThread(new Runnable() {

                public void run() {
                    progressBar.setProgress(progress);
                }
            });
        }
    });
    EMClient.getInstance().chatManager().downloadAttachment(message);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) EMFileMessageBody(com.hyphenate.chat.EMFileMessageBody) File(java.io.File) EMMessage(com.hyphenate.chat.EMMessage)

Aggregations

EMCallBack (com.hyphenate.EMCallBack)1 EMFileMessageBody (com.hyphenate.chat.EMFileMessageBody)1 EMMessage (com.hyphenate.chat.EMMessage)1 File (java.io.File)1