com.easemob.chat.FileMessageBody Java Examples
The following examples show how to use
com.easemob.chat.FileMessageBody.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseShowNormalFileActivity.java From monolog-android with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ease_activity_show_file); progressBar = (ProgressBar) findViewById(R.id.progressBar); final FileMessageBody messageBody = getIntent().getParcelableExtra("msgbody"); file = new File(messageBody.getLocalUrl()); //set head map final Map<String, String> maps = new HashMap<String, String>(); if (!TextUtils.isEmpty(messageBody.getSecret())) { maps.put("share-secret", messageBody.getSecret()); } //下载文件 EMChatManager.getInstance().downloadFile(messageBody.getRemoteUrl(), messageBody.getLocalUrl(), maps, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { FileUtils.openFile(file, EaseShowNormalFileActivity.this); finish(); } }); } @Override public void onProgress(final int progress,String status) { runOnUiThread(new Runnable() { public void run() { progressBar.setProgress(progress); } }); } @Override public void onError(int error, final String msg) { 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+msg, Toast.LENGTH_SHORT).show(); finish(); } }); } }); }
Example #2
Source File: ShowNormalFileActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_file); progressBar = (ProgressBar) findViewById(R.id.progressBar); final FileMessageBody messageBody = getIntent().getParcelableExtra("msgbody"); file = new File(messageBody.getLocalUrl()); //set head map final Map<String, String> maps = new HashMap<String, String>(); if (!TextUtils.isEmpty(messageBody.getSecret())) { maps.put("share-secret", messageBody.getSecret()); } //下载文件 new Thread(new Runnable() { public void run() { HttpFileManager fileManager = new HttpFileManager(ShowNormalFileActivity.this, EMChatConfig.getInstance().getStorageUrl()); fileManager.downloadFile(messageBody.getRemoteUrl(), messageBody.getLocalUrl(), maps, new CloudOperationCallback() { @Override public void onSuccess(String result) { runOnUiThread(new Runnable() { public void run() { FileUtils.openFile(file, ShowNormalFileActivity.this); finish(); } }); } @Override public void onProgress(final int progress) { runOnUiThread(new Runnable() { public void run() { progressBar.setProgress(progress); } }); } @Override public void onError(final String msg) { runOnUiThread(new Runnable() { public void run() { if(file != null && file.exists()&&file.isFile()) file.delete(); Toast.makeText(ShowNormalFileActivity.this, "下载文件失败: "+msg, Toast.LENGTH_SHORT).show(); finish(); } }); } }); } }).start(); }