// 下载图片到本地
@android.webkit.JavascriptInterface
public void getImg(final String imgUrl) {
loadingDialog = new BjrsProgressDialog(activity);
loadingDialog.show();
File sdCard = Environment.getExternalStorageDirectory();
File directory_GetImg = new File(sdCard, "image");
final String savepath = directory_GetImg + "/" + DataDispose.getStringMD5(imgUrl) + ".jpg";
new Thread(new Runnable() {
@Override
public void run() {
final FileLoader fl = new FileLoader();
File f = new File(savepath);
if (fl.loadNetFile(imgUrl, savepath)) {
// 延时操作
TimerTask task = new TimerTask() {
@Override
public void run() {
if (loadingDialog != null && loadingDialog.isShowing()) {
Log.d("下载提示(子线程中)", "加载框关闭了");
loadingDialog.dismiss();
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
File f = new File(savepath);
if (f.exists() || f.length() != 0) {
Toast.makeText(activity, "图片已保存到->" + savepath, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, "图片已保存到->" + savepath, Toast.LENGTH_SHORT).show();
}
}
});
}
};
Timer timer = new Timer();
timer.schedule(task, 1000);//1秒后执行TimeTask的run方法
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(f));
activity.sendBroadcast(intent);
}
}
}).start();
}
// 分享考试结果
@android.webkit.JavascriptInterface
public void share(final String titletextStr, final String sharecontent,
final String shareImgUrl, final String shareUrl) {
loadingDialog = new BjrsProgressDialog(activity);
loadingDialog.show();
ImageLoader.loadImage(shareImgUrl, ApplicationApp.savePath + "/img/" + DataDispose.getStringMD5(shareImgUrl), new ImageLoader.ImageCallBack() {
@Override
public void imageLoaded(boolean loadSuccess, String imageUrl, Bitmap bitmap) {
if (loadingDialog != null && loadingDialog.isShowing())
loadingDialog.dismiss();
shareBitmap = bitmap;
Log.d("分享操作", "进入了分享子线程");
Log.d("分享操作 Url", "loadSuccess=" + loadSuccess + " " + shareImgUrl);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// 打开分享提示框
ApplicationApp.shareSDK.setShareContent(titletextStr, sharecontent, titletextStr,
shareUrl, shareImgUrl, shareBitmap, R.drawable.ic_launcher128);
ApplicationApp.shareSDK.adddialog_share1(activity, BaseDialog.STYLE_BOTTOM_TRAN_DARK, titletextStr);
}
});
}
});
Log.d("分享操作", "点击了分享");
}
android 与 js 交互实例
最新推荐文章于 2023-03-21 15:23:47 发布