我正在尝试使用“ barteksc”库创建pdf查看器。当我使用pdfview.fromAssets(“ pdffile.pdf”)从“资产”文件夹添加pdf文件时,它可以工作,但使用文件路径却不起作用。我使用“ BrowserActivity”中的按钮浏览pdf文件,选择文件后它将文件路径发送到MainActivity。在Mainactivity中,我无法使用pip install mysqlclient
pdfview.fromFile("filen");
}
public class BrowserActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
Button button = findViewById(R.id.browse);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, 7);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch (requestCode) {
case 7:
if (resultCode == RESULT_OK) {
String PathHolder = data.getData().getPath();
Toast.makeText(BrowserActivity.this, PathHolder, Toast.LENGTH_LONG).show();
Intent intent = new Intent(BrowserActivity.this, MainActivity.class);
intent.putExtra("path", PathHolder);
startActivity(intent);
}
break;
}
}
}