Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Visualizador_pdf extends AppCompatActivity {
- private TextView textView;
- private File file;
- //Declaracions de la conexió:
- private static final String TAG = "Visualizador_pdf";
- public static Context cntx = null;
- private static final String HOST = "ftp.appdesigndm.com";
- private static final String USER = "master@appdesigndm.com";
- private static final String PASS = "Alin1022";
- public static FTPClient mFTPClient = null;
- String srcFilePath = "";
- String desFileStream = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/PDF/" + "des.pdf";
- //-------------------------------------------------------------------------------------------------------------------------------
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_visualizador_pdf);
- cntx = this;
- mFTPClient = new FTPClient();
- //String ruta = "";
- //file = new File(ruta);
- //textView = (TextView) findViewById(R.id.text);
- Intent intent = getIntent();
- Bundle extras = intent.getExtras();
- if (extras != null) {
- srcFilePath = extras.getString("PDF");
- Toast.makeText(getApplicationContext(), srcFilePath, Toast.LENGTH_LONG).show();
- HiloDescarga hilo = new HiloDescarga();
- hilo.execute(srcFilePath, desFileStream);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- //llamarpdf();
- }
- }
- public static boolean download(String srcFilePath, String desFilePath) {
- boolean status = false;
- try {
- File f = new File(desFilePath.substring(0, desFilePath.lastIndexOf("/") + 1));
- if (!f.exists()) {
- f.mkdirs();
- }
- FileOutputStream desFileStream = new FileOutputStream(desFilePath);
- mFTPClient.connect(HOST);
- mFTPClient.login(USER, PASS);
- status = mFTPClient.retrieveFile(srcFilePath, desFileStream);
- desFileStream.close();
- return status;
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- Log.d(TAG, "download failed");
- } finally {
- try {
- mFTPClient.disconnect();
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- }
- }
- return status;
- }
- public void llamarpdf() {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/PDF/" + "des.pdf";
- File file = new File(path);
- Intent aviso = new Intent(Intent.ACTION_VIEW);
- aviso.setDataAndType(Uri.fromFile(file), "application/pdf");
- aviso.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- Intent intent = Intent.createChooser(aviso, "Open file");
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException e) {
- }
- finish();
- }
- @Override
- protected void onStop() {
- super.onStop();
- }
- }
Add Comment
Please, Sign In to add comment