如何解码编码的base64字符串并将其下载为Android中的PDF?
我正在通过API获取/下载编码的base64字符串,现在我必须将其解码为64,然后在解码base64字符串后,我需要将其转换为PDF文件。因此,当我单击下载按钮时它会给我转换后的解码base64作为pdf。
代码:
Context context;
List<BillReceiptReport> list;
UtilityBillManager manager;
String encodedBase64 = "";
public BillReportDetailsAdapter(Context context, List<BillReceiptReport> list) {
this.context = context;
this.list = list;
}
@Override
public BillReportDetailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new BillReportDetailsViewHolder(LayoutInflater.from(context).inflate(R.layout.transaction_reports_details_item_layout, parent, false));
}
@Override
public void onBindViewHolder(@NonNull BillReportDetailsViewHolder holder, int position) {
BillReceiptReport billReceiptReport = list.get(position);
holder.downloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager = new UtilityBillManager(context, AppBaseController.get().getUserSettings());
manager.UserTransactionReceiptReport(listener,billReceiptReport); //UserTransactionReceiptReport is the api where i get the base64 string from server.
}
});
}
private final TransactionReportListener listener = new TransactionReportListener() {
@Override
public void didFetch(String response, String message) {
encodedBase64 = response;
//Log.e("tag",encodedBase64);
byte [] decodeBase64 = android.util.Base64.decode(encodedBase64, Base64.DEFAULT);
//现在我有了解码的base64字符串,现在我需要将其显示为pdfview。
}
@Override
public void didError(String message) {
}
};
我认为现在我的问题是对您的理解
I am getting/ downloading the encoded base64 string through api, Now I have to decoding it to base 64, and then after decoding the base64 string, I need to convert it as pdf file.so that when I click the downloading button it will give me the converted decoding base64 as PDF.
Code:
Context context;
List<BillReceiptReport> list;
UtilityBillManager manager;
String encodedBase64 = "";
public BillReportDetailsAdapter(Context context, List<BillReceiptReport> list) {
this.context = context;
this.list = list;
}
@Override
public BillReportDetailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new BillReportDetailsViewHolder(LayoutInflater.from(context).inflate(R.layout.transaction_reports_details_item_layout, parent, false));
}
@Override
public void onBindViewHolder(@NonNull BillReportDetailsViewHolder holder, int position) {
BillReceiptReport billReceiptReport = list.get(position);
holder.downloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager = new UtilityBillManager(context, AppBaseController.get().getUserSettings());
manager.UserTransactionReceiptReport(listener,billReceiptReport); //UserTransactionReceiptReport is the api where i get the base64 string from server.
}
});
}
private final TransactionReportListener listener = new TransactionReportListener() {
@Override
public void didFetch(String response, String message) {
encodedBase64 = response;
//Log.e("tag",encodedBase64);
byte [] decodeBase64 = android.util.Base64.decode(encodedBase64, Base64.DEFAULT);
// Now i have the decoded base64 string, Now i need to showing it as pdfview.
}
@Override
public void didError(String message) {
}
};
I think now my question is understanding to you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论