[e68708b] | 1 | package ve.gob.cenditel.tibisaymovil; |
---|
| 2 | |
---|
| 3 | import java.io.BufferedInputStream; |
---|
| 4 | import java.io.File; |
---|
| 5 | import java.io.InputStream; |
---|
| 6 | |
---|
| 7 | import android.net.Uri; |
---|
| 8 | import android.os.Bundle; |
---|
| 9 | import android.app.Activity; |
---|
| 10 | import android.content.Context; |
---|
| 11 | import android.content.Intent; |
---|
| 12 | import android.util.Log; |
---|
| 13 | import android.view.LayoutInflater; |
---|
| 14 | import android.view.View; |
---|
| 15 | import android.view.ViewGroup; |
---|
| 16 | import android.view.Window; |
---|
| 17 | import android.view.View.OnClickListener; |
---|
[42e7061] | 18 | import android.webkit.MimeTypeMap; |
---|
[e68708b] | 19 | import android.widget.AdapterView; |
---|
| 20 | import android.widget.BaseAdapter; |
---|
| 21 | import android.widget.ImageView; |
---|
| 22 | import android.widget.LinearLayout; |
---|
| 23 | import android.widget.ListView; |
---|
| 24 | import android.widget.TextView; |
---|
| 25 | import android.widget.Toast; |
---|
| 26 | |
---|
| 27 | import java.security.*; |
---|
| 28 | import java.security.cert.Certificate; |
---|
| 29 | import java.security.cert.CertificateFactory; |
---|
| 30 | import java.io.*; |
---|
| 31 | import java.lang.reflect.Field; |
---|
| 32 | |
---|
| 33 | import com.lowagie.text.pdf.*; |
---|
| 34 | |
---|
| 35 | import ee.sk.digidoc.SignedDoc; |
---|
| 36 | import ee.sk.utils.ConvertUtils; |
---|
| 37 | |
---|
| 38 | import java.util.Calendar; |
---|
| 39 | import java.util.ArrayList; |
---|
| 40 | import java.util.Random; |
---|
| 41 | import java.security.cert.X509Certificate; |
---|
| 42 | import java.text.SimpleDateFormat; |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | public class PDFVerifyResultActivity extends Activity { |
---|
| 52 | |
---|
| 53 | private LinearLayout button_share; |
---|
| 54 | private LinearLayout button_finish; |
---|
| 55 | |
---|
[c14b8d2] | 56 | // ruta absoluta al archivo a verificar |
---|
[e68708b] | 57 | private String pdfToVerify; |
---|
| 58 | |
---|
| 59 | @Override |
---|
| 60 | protected void onCreate(Bundle savedInstanceState) { |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | //Estilando la barra de titulo |
---|
| 65 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
| 66 | |
---|
| 67 | super.onCreate(savedInstanceState); |
---|
| 68 | |
---|
| 69 | setContentView(R.layout.activity_verify_result_pdf); |
---|
| 70 | |
---|
| 71 | //Estilando Barra de titulo |
---|
| 72 | if(customTitleSupported) |
---|
| 73 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
| 74 | |
---|
| 75 | // obtener el archivo pdf a verificar |
---|
| 76 | Bundle bundle = getIntent().getExtras(); |
---|
| 77 | pdfToVerify = bundle.getString("pdfToVerify"); |
---|
| 78 | TextView pdfName = (TextView) this.findViewById(R.id.filename_text); |
---|
| 79 | pdfName.setText(pdfToVerify); |
---|
| 80 | |
---|
| 81 | // ejecutar el proceso de verificacion del pdf |
---|
| 82 | doVerification(pdfToVerify); |
---|
| 83 | |
---|
[42e7061] | 84 | LinearLayout layoutPdfFileResult = (LinearLayout) this.findViewById(R.id.layout_pdf_signed_result); |
---|
| 85 | |
---|
| 86 | OnClickListener pdfFileListener = new OnClickListener() { |
---|
| 87 | public void onClick(View v) { |
---|
| 88 | |
---|
| 89 | //Toast.makeText(getApplicationContext(), "**CLICK SOBRE EL archivo***", Toast.LENGTH_LONG).show(); |
---|
| 90 | |
---|
| 91 | openIt(pdfToVerify, getMimeType(pdfToVerify)); |
---|
| 92 | } |
---|
| 93 | }; |
---|
| 94 | layoutPdfFileResult.setOnClickListener(pdfFileListener); |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
[e68708b] | 98 | // habilitar opciones de botones inferiores |
---|
| 99 | button_share = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); |
---|
| 100 | button_finish = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); |
---|
| 101 | |
---|
| 102 | // habilita el click sobre la acción de finalizar la verificacion de firma y regresar |
---|
| 103 | button_finish.setOnClickListener(new OnClickListener() |
---|
| 104 | { |
---|
| 105 | public void onClick(View v) |
---|
| 106 | { |
---|
| 107 | |
---|
| 108 | Intent oIntent = new Intent(PDFVerifyResultActivity.this, TibisayMovilActivity.class); |
---|
| 109 | oIntent.setAction(Intent.ACTION_VIEW); |
---|
| 110 | oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
| 111 | startActivity(oIntent); |
---|
| 112 | |
---|
| 113 | finish(); |
---|
| 114 | } |
---|
| 115 | }); |
---|
| 116 | |
---|
| 117 | // habilita el click sobre la acción de compartir el archivo |
---|
| 118 | button_share.setOnClickListener(new OnClickListener() |
---|
| 119 | { |
---|
| 120 | public void onClick(View v) |
---|
| 121 | { |
---|
| 122 | shareIt(); |
---|
| 123 | } |
---|
| 124 | }); |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | } // fin de onCreate |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * Ejecuta la verificacion de la firma del pdf utilizando la biblioteca droidtext |
---|
| 133 | * |
---|
| 134 | * */ |
---|
| 135 | private void doVerification(String pdfToVerify) { |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | try { |
---|
| 139 | |
---|
| 140 | Random rnd = new Random(); |
---|
| 141 | |
---|
| 142 | PdfReader reader = new PdfReader(pdfToVerify); |
---|
| 143 | Log.d("VerificadorPDF", "new PdfReader"); |
---|
| 144 | |
---|
| 145 | AcroFields af = reader.getAcroFields(); |
---|
| 146 | Log.d("VerificadorPDF", "reader.getAcroFields()"); |
---|
| 147 | |
---|
| 148 | ArrayList names = af.getSignatureNames(); |
---|
| 149 | Log.d("VerificadorPDF", "af.getSignatureNames()"); |
---|
| 150 | |
---|
| 151 | Toast.makeText(getApplicationContext(), "names.size: "+ Integer.toString(names.size()), Toast.LENGTH_SHORT).show(); |
---|
| 152 | Log.d("VerificadorPDF", Integer.toString(names.size())); |
---|
| 153 | |
---|
| 154 | if (names.size() == 0) { |
---|
| 155 | // el archivo no posee firmas |
---|
| 156 | TextView signatureMessage = (TextView) this.findViewById(R.id.archivo_original_a_descifrar); |
---|
| 157 | signatureMessage.setText("El documento PDF no está firmado electrónicamente."); |
---|
| 158 | |
---|
| 159 | TextView labelSignature = (TextView) this.findViewById(R.id.label_archivo_original); |
---|
| 160 | labelSignature.setText("Documento:"); |
---|
| 161 | |
---|
| 162 | TextView labelSigners = (TextView) this.findViewById(R.id.label_destinatario_cifrado); |
---|
| 163 | labelSigners.setVisibility(View.GONE); |
---|
| 164 | |
---|
| 165 | ListView listViewSigners = (ListView) this.findViewById(R.id.signatures_list); |
---|
| 166 | listViewSigners.setVisibility(View.GONE); |
---|
| 167 | return; |
---|
| 168 | }else{ |
---|
| 169 | // el documento si posee firmas |
---|
| 170 | //KeyStore kall = PdfPKCS7.loadCacertsKeyStore(); |
---|
| 171 | |
---|
| 172 | // crear certificate factory |
---|
| 173 | CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
---|
| 174 | |
---|
| 175 | // crear un KeyStore |
---|
| 176 | String keyStoreType = KeyStore.getDefaultType(); |
---|
| 177 | KeyStore kall = KeyStore.getInstance(keyStoreType); |
---|
| 178 | kall.load(null, null); |
---|
| 179 | |
---|
| 180 | // obtener vector de campos de /res/raw |
---|
| 181 | Field[] fields = R.raw.class.getFields(); |
---|
| 182 | |
---|
| 183 | InputStream caInput = null; |
---|
| 184 | |
---|
| 185 | // iterar sobre todos los certificados incluidos en /res/raw y cargarlos |
---|
| 186 | // en el KeyStore |
---|
| 187 | for (int l=0; l < fields.length; l++) { |
---|
| 188 | try { |
---|
[42e7061] | 189 | //Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity - reading certificate: "+Integer.toString(l)+ " "+ |
---|
| 190 | // Integer.toString(fields[l].getInt(null)), Toast.LENGTH_SHORT).show(); |
---|
[e68708b] | 191 | |
---|
| 192 | caInput = new BufferedInputStream(getResources().openRawResource(fields[l].getInt(null))); |
---|
| 193 | |
---|
| 194 | } catch (IllegalArgumentException e) { |
---|
| 195 | |
---|
| 196 | Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity: IllegalArgumentException "+e.getMessage(), |
---|
| 197 | Toast.LENGTH_SHORT).show(); |
---|
| 198 | break; |
---|
| 199 | } catch (IllegalAccessException e) { |
---|
| 200 | |
---|
| 201 | Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity: IllegalAccessException "+e.getMessage(), |
---|
| 202 | Toast.LENGTH_SHORT).show(); |
---|
| 203 | break; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | Certificate ca; |
---|
| 207 | try { |
---|
| 208 | ca = cf.generateCertificate(caInput); |
---|
| 209 | //Log.d("**ca:", ((X509Certificate) ca).getSubjectDN()); |
---|
| 210 | |
---|
| 211 | //Log.d("*** try: ca.toString()", ca.toString()); |
---|
| 212 | } finally { |
---|
| 213 | caInput.close(); |
---|
| 214 | } |
---|
| 215 | kall.setCertificateEntry("ca"+Integer.toString(l), ca); |
---|
| 216 | }// fin de la iteracion sobre /res/raw |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | // se crea el adaptador para mostrar los firmantes del contenedor |
---|
| 220 | ListView signerListView = (ListView) findViewById(R.id.signatures_list); |
---|
| 221 | final ArrayList<SignerFromPDF> signers = new ArrayList<SignerFromPDF>(); |
---|
| 222 | |
---|
| 223 | boolean invalidSignature = false; |
---|
| 224 | |
---|
| 225 | for (int i = 0; i < names.size(); i++){ |
---|
| 226 | |
---|
| 227 | String name = (String)names.get(i); |
---|
| 228 | PdfPKCS7 pk = af.verifySignature(name); |
---|
| 229 | Calendar cal = pk.getSignDate(); |
---|
| 230 | Certificate pkc[] = pk.getCertificates(); |
---|
| 231 | |
---|
| 232 | X509Certificate cert = (X509Certificate) pk.getSigningCertificate(); |
---|
| 233 | |
---|
| 234 | String cn = cert.getSubjectDN().toString(); |
---|
| 235 | String signerName = ConvertUtils.getCommonName(cn); |
---|
| 236 | |
---|
| 237 | SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS"); |
---|
| 238 | String date = date_format.format(pk.getSignDate().getTime()); |
---|
| 239 | |
---|
| 240 | String certificateSerial = cert.getSerialNumber().toString(); |
---|
| 241 | String validFrom = cert.getNotBefore().toString(); |
---|
| 242 | String validUntil = cert.getNotAfter().toString(); |
---|
| 243 | String certificateIssuer = cert.getIssuerDN().toString(); |
---|
| 244 | |
---|
| 245 | Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal); |
---|
| 246 | if (fails == null) { |
---|
| 247 | System.out.print(pk.getSignName()); |
---|
| 248 | Toast.makeText(getApplicationContext(), "Firma Válida", Toast.LENGTH_SHORT).show(); |
---|
| 249 | } |
---|
| 250 | else { |
---|
| 251 | System.out.print("Firma no válida"); |
---|
| 252 | Toast.makeText(getApplicationContext(), "Firma NO Válida", Toast.LENGTH_SHORT).show(); |
---|
| 253 | |
---|
| 254 | invalidSignature = true; |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | // agregar el nombre comun del firmante y la fecha y la hora |
---|
| 258 | signers.add(new SignerFromPDF(signerName, cn, date, certificateSerial, validFrom, validUntil, certificateIssuer)); |
---|
| 259 | |
---|
| 260 | TextView signatureValidation = (TextView) this.findViewById(R.id.archivo_original_a_descifrar); |
---|
| 261 | |
---|
| 262 | if (invalidSignature){ |
---|
| 263 | signatureValidation.setText("Firma Inválida"); |
---|
| 264 | }else{ |
---|
| 265 | signatureValidation.setText("Firma Válida"); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | SignerFromPDFAdapter signerAdapter = new SignerFromPDFAdapter(PDFVerifyResultActivity.this, signers); |
---|
| 272 | signerListView.setAdapter(signerAdapter); |
---|
| 273 | signerListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | @Override |
---|
| 277 | public void onItemClick(AdapterView<?> parent, View view, |
---|
| 278 | int position, long id) { |
---|
| 279 | |
---|
| 280 | Toast.makeText(getApplicationContext(), "SE DEBE MOSTRAR INFORMACIÓN DEL FIRMANTE", Toast.LENGTH_SHORT).show(); |
---|
| 281 | showSignatureDetails(position, signers); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | }); |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | } // fin de else: el documento posee firmas |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | }catch(Exception e){ |
---|
| 292 | Toast.makeText(getApplicationContext(), "Error al verificar pdf:"+e.getMessage(), Toast.LENGTH_LONG).show(); |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | // funcion para compartir el documento |
---|
| 299 | private void shareIt() { |
---|
| 300 | |
---|
| 301 | Intent shareIntent = new Intent(); |
---|
| 302 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
| 303 | File file = new File(pdfToVerify); |
---|
| 304 | |
---|
| 305 | |
---|
| 306 | Uri uri = Uri.fromFile(file); |
---|
| 307 | Log.i("DEBUG", file.getPath()); |
---|
| 308 | //Log.d("******", getMimeType(file.getPath())); |
---|
| 309 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
| 310 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
| 311 | shareIntent.setType("application/*"); |
---|
| 312 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | // class que abstrae un firmante incluido en un contenedor BDOC |
---|
| 317 | private class SignerFromPDF { |
---|
| 318 | |
---|
| 319 | // nombre del firmante |
---|
| 320 | private String mName; |
---|
| 321 | |
---|
| 322 | // nombre comun del firmante |
---|
| 323 | private String mCN; |
---|
| 324 | |
---|
| 325 | // fecha y hora de la firma |
---|
| 326 | private String mDate; |
---|
| 327 | |
---|
| 328 | // serial del certificado |
---|
| 329 | private String mCertificateSerial; |
---|
| 330 | |
---|
| 331 | // fecha de validez inicial |
---|
| 332 | private String mValidFrom; |
---|
| 333 | |
---|
| 334 | // fecha de validez final |
---|
| 335 | private String mValidUntil; |
---|
| 336 | |
---|
| 337 | // emisor del certificado |
---|
| 338 | private String mCertificateIssuer; |
---|
| 339 | |
---|
| 340 | public SignerFromPDF(String name, String cn, String date, String serial, String validFrom, String validUntil, String issuer){ |
---|
| 341 | mName = name; |
---|
| 342 | mCN = cn; |
---|
| 343 | mDate = date; |
---|
| 344 | mCertificateSerial = serial; |
---|
| 345 | mValidFrom = validFrom; |
---|
| 346 | mValidUntil = validUntil; |
---|
| 347 | mCertificateIssuer = issuer; |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | public void setName(String name) { |
---|
| 351 | this.mName = name; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | public String getName() { |
---|
| 355 | return mName; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | public void setCN(String cn) { |
---|
| 359 | this.mCN = cn; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | public String getCN() { |
---|
| 363 | return mCN; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | public void setDate(String date) { |
---|
| 367 | this.mDate = date; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | public String getDate() { |
---|
| 371 | return mDate; |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | public void setCertificateSerial(String certSerial) { |
---|
| 375 | this.mCertificateSerial = certSerial; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | public String getCertificateSerial() { |
---|
| 379 | return mCertificateSerial; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | public void setValidFrom(String validFrom) { |
---|
| 383 | this.mValidFrom = validFrom; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | public String getValidFrom() { |
---|
| 387 | return mValidFrom; |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | public void setValidUntil(String validUntil) { |
---|
| 391 | this.mValidUntil = validUntil; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | public String getValidUntil() { |
---|
| 395 | return mValidUntil; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | public void setCertificateIssuer(String certIssuer) { |
---|
| 399 | this.mCertificateIssuer = certIssuer; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | public String getCertificateIssuer() { |
---|
| 403 | return mCertificateIssuer; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | } // fin de clase SignerFromPDF |
---|
| 407 | |
---|
| 408 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
| 409 | // se encuentran dentro del contenedor BDOC |
---|
| 410 | private class SignerFromPDFAdapter extends BaseAdapter { |
---|
| 411 | |
---|
| 412 | private ArrayList<SignerFromPDF> mSignerFromPDFList; |
---|
| 413 | private LayoutInflater lInflater; |
---|
| 414 | |
---|
| 415 | private SignerFromPDFAdapter(Context context, ArrayList<SignerFromPDF> signers) { |
---|
| 416 | this.lInflater = LayoutInflater.from(context); |
---|
| 417 | this.mSignerFromPDFList = signers; |
---|
| 418 | |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | |
---|
| 422 | @Override |
---|
| 423 | public int getCount() { |
---|
| 424 | return mSignerFromPDFList.size(); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | @Override |
---|
| 428 | public Object getItem(int position) { |
---|
| 429 | return mSignerFromPDFList.get(position); |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | @Override |
---|
| 433 | public long getItemId(int position) { |
---|
| 434 | return position; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | @Override |
---|
| 438 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
| 439 | ViewHolder container = null; |
---|
| 440 | |
---|
| 441 | if (convertView == null){ |
---|
| 442 | container = new ViewHolder(); |
---|
| 443 | convertView = lInflater.inflate(R.layout.signer_inside_bdoc_item, null); |
---|
| 444 | |
---|
| 445 | container.signer_text = (TextView) convertView.findViewById(R.id.signer_info); |
---|
| 446 | container.signer_modified = (TextView) convertView.findViewById(R.id.signature_errors); |
---|
| 447 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
| 448 | convertView.setTag(container); |
---|
| 449 | }else{ |
---|
| 450 | container = (ViewHolder) convertView.getTag(); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | SignerFromPDF doc = (SignerFromPDF) getItem(position); |
---|
| 454 | container.signer_text.setText(doc.getName()); |
---|
| 455 | container.signer_modified.setText(doc.getName()); |
---|
| 456 | container.type_image.setImageResource(R.drawable.ic_pluma); |
---|
| 457 | |
---|
| 458 | return convertView; |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | class ViewHolder{ |
---|
| 463 | TextView signer_text; |
---|
| 464 | TextView signer_modified; |
---|
| 465 | ImageView type_image; |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | /** |
---|
| 471 | * Lanza la actividad para mostrar detalles de un firmante |
---|
| 472 | * |
---|
| 473 | * */ |
---|
| 474 | private void showSignatureDetails(int position, ArrayList<SignerFromPDF> signers) { |
---|
| 475 | |
---|
| 476 | Log.d("**showSignatureDetails", Integer.toString(position)); |
---|
| 477 | Log.d("** nombre", signers.get(position).getName()); |
---|
| 478 | Intent intent = new Intent(this, ActivitySignerInfo.class); |
---|
| 479 | |
---|
| 480 | intent.putExtra("name", signers.get(position).getName()); |
---|
| 481 | intent.putExtra("cn", signers.get(position).getCN()); |
---|
| 482 | intent.putExtra("date", signers.get(position).getDate()); |
---|
| 483 | intent.putExtra("certificateSerial", signers.get(position).getCertificateSerial()); |
---|
| 484 | intent.putExtra("validFrom", signers.get(position).getValidFrom()); |
---|
| 485 | intent.putExtra("validUntil", signers.get(position).getValidUntil()); |
---|
| 486 | intent.putExtra("certificateIssuer", signers.get(position).getCertificateIssuer()); |
---|
| 487 | startActivity(intent); |
---|
| 488 | } |
---|
| 489 | |
---|
[42e7061] | 490 | // funcion para obtener el tipo mime de un archivo |
---|
| 491 | public static String getMimeType(String url) |
---|
| 492 | { |
---|
| 493 | String extension = url.substring(url.lastIndexOf(".")); |
---|
| 494 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
| 495 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
| 496 | return mimeType; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | |
---|
| 500 | // funcion para lanzar un intent que abra un archivo |
---|
| 501 | private void openIt(String pdfFile, String mimeType) { |
---|
| 502 | |
---|
| 503 | Intent shareIntent = new Intent(); |
---|
| 504 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
| 505 | File file = new File(pdfFile); |
---|
| 506 | Uri uri = Uri.fromFile(file); |
---|
| 507 | Log.i("DEBUG", file.getPath()); |
---|
| 508 | shareIntent.setDataAndType(uri, mimeType); |
---|
| 509 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
| 510 | } |
---|
[e68708b] | 511 | |
---|
| 512 | } |
---|