How to open MIME - type "application / x-509-server-cert" in Android Moto G?

Here is a strange case with Moto G. I am trying to open the server certificate file in android programmatically and then install it. I use below code to make it work. It works for all devices except Moto G, and displays a message with a toast: "Failed to install because the certificate file could not be read." Another strange thing I discovered is that Moto G finds the MIME type of this certificate file as completely different from other devices:

Note 2 - application/x-509-user-cert
Moto G - application/x-509-server-cert
Verizon - application/x-509-user-cert
Samsung Nexus - application/x-509-user-cert
Sony - application/x-509-user-cert

How can I actually open this particular MIME type = "application / x-509-server-cert" in Moto G. For the safer side, I am not where the MIME type is for hard coding and opening it. I actually let android identify and then do whatever it wants

protected void openFile() {

                File vpnCerti = new File("/sdcard/VPNCertificate/Install.crt");

                //Mime Type Info : http://webdesign.about.com/od/multimedia/a/mime-types-by-content-type.htm

                //Identify MIME types
                Uri path = Uri.fromFile(vpnCerti);
                MimeTypeMap type_map = MimeTypeMap.getSingleton();
                //Get the extension from the path
                String extension = MimeTypeMap.getFileExtensionFromUrl(path.toString());
                extension = extension.toLowerCase();
                if (extension.contains(".")) {
                    extension = extension.substring(extension.lastIndexOf("."));
                }
                String mime_type = type_map.getMimeTypeFromExtension(extension);
                Log.d("DownloadManager", "MIME Type : " + mime_type);
                //Identify MIME types ends

                Intent i = new Intent();
                i.setAction(android.content.Intent.ACTION_VIEW);
                //i.setDataAndType(Uri.fromFile(vpnCerti), "application/x-x509-server-cert");
                i.setDataAndType(Uri.fromFile(vpnCerti), mime_type);

                startActivity(i);




            }
+4
source share

Source: https://habr.com/ru/post/1531508/


All Articles