Commit a8377931 by yuichiro ogawa

#38370 PDFダウンロード処理の実装

parent 288b8b71
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_enabled="false"
android:drawable="@drawable/home_print_off"/>
<item
android:drawable="@drawable/home_print_white"/>
</selector>
\ No newline at end of file
......@@ -133,7 +133,7 @@
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/btn_operation_print"
android:background="@drawable/btn_operation_print_white"
android:contentDescription="@string/print"
android:visibility="gone" />
......
package jp.agentec.abook.abv.launcher.android;
import java.io.File;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.log.Logger;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.log.Logger;
import static android.content.ContentValues.TAG;
/**
* 新しいAPKのダウンロードが完了したときの通知を受け取る
* @author jang
......@@ -26,6 +30,25 @@ public class OnAppDownloadReceiver extends BroadcastReceiver {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
Logger.d("Download Complete ID : " + id);
DownloadManager dm = (DownloadManager)context.getSystemService(context.DOWNLOAD_SERVICE);
final Cursor cursor;
if (dm != null) {
cursor = dm.query(
new DownloadManager.Query().setFilterById(id));
if (cursor.moveToFirst()) {
final String downloadedTo = cursor.getString(
cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
Log.d(TAG, "The file has been downloaded to: " + downloadedTo);
if (downloadedTo != null && downloadedTo.endsWith(".pdf")) {
Toast.makeText(context, context.getResources().getString(R.string.download_success), //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
// PDFファイルの場合はAPK用の処理は通過させない
return;
}
}
}
if (id == -1) {
// ダウンロードマネージャの通知領域をクリックした場合はメッセージ表示のみ
Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();
......
package jp.agentec.abook.abv.ui.viewer.activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Map;
......@@ -92,6 +99,36 @@ public class OnlineHTMLWebViewActivity extends ABVContentViewActivity {
return false;
}
});
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
final String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
request.setMimeType(mimetype);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setTitle(fileName);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
if (dm != null) {
dm.enqueue(request);
}
Toast.makeText(getApplicationContext(), getString(R.string.download_start), //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
}
});
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment