java - 如何从警报对话框界面传递用户输入的密码以打开受密码保护的 pdf 文件?
问题描述
我barteksc
在我的 pdf 应用程序中使用,我想将用户从警报对话框中输入的密码值传递setPositiveButton
给“.password()”,以打开受密码保护的 pdf 文件。在onError
侦听器中,我正在调用打开AlertDialog
.onError(new OnErrorListener() {
@Override
public void onError(Throwable t) {
if (t instanceof PdfPasswordException){
showPasswordDialog();
}
}
})
这是方法的代码
private void showPasswordDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Password:")
.setIcon(R.drawable.ic_key)
.setMessage("Enter Password to open pdf");
final EditText input = new EditText(PdfActivity.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(layoutParams);
builder.setView(input);
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//implement cancel button
dialogInterface.cancel();
}
})
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//implement a check that the password is correct
}
});
builder.show();
}
解决方案
推荐阅读
- python - 在 1D-NumPy 数组中查找奇异值/局部最大值/最小值集(再次)
- excel - 将打开的工作簿列表添加到组合框并将相关工作表添加到列表框(VBA Excel)
- jquery - 如何根据输入类型 number*$(value) 对值求和
- neo4j - 在 Neo4j 中检索具有可变长度关系的中间节点
- c# - 我们如何在 c# 中遍历 JSON 数据中的子节点
- javascript - “this”反应高阶组件
- javascript - 布尔公式
- excel - 将宏限制为活动工作表
- c - Initializing struct member of type struct pointer to null
- javascript - 下一条语句没有被执行 - jQuery