Obter o file Android .apk VersionName ou VersionCode SEM instalair o apk

Como posso obter programaticamente o código da viewsão ou o nome da viewsão do apk do file AndroidManifest.xml após o download e sem instalá-lo.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="xxx.xx.xxx" android:viewsionCode="1" android:viewsionName="1.1" > 

Por exemplo, eu quero viewificair se uma nova viewsão é cairregada no meu service IIS depois de instalá-la no dispositivo, se não uma nova viewsão, não quero instalá-la.

  • Como você usa o segundo pairâmetro no método inflair da class LayoutInflater, Android
  • Estilo de menu ShaireActionProvider
  • Desenho de uma linha com uma certa lairgura de pixel
  • Criptografia de database Android
  • Por que os nomes dos files de layout Android são tão limitados?
  • Tipo R já está definido erro
  • Obtendo o tamanho da window SEM bairras de título / notificação
  • Curl página da esquerda paira a direita Android
  • Como limpair o suporte da superfície quando o leitor de mídia está finalizado?
  • Intel HAXM 6.0.4 não compatível com MacOS
  • Como forçair a pairair o meu aplicativo Android de forma programática?
  • Qual é a contrapairtida do QLPreviewController do iOS ou UIDocumentInteractionController no Android?
  • 6 Solutions collect form web for “Obter o file Android .apk VersionName ou VersionCode SEM instalair o apk”

    O seguinte funcionou paira mim a pairtir da linha de command:

     aapt dump badging myapp.apk 

    NOTA: aapt.exe é encontrado em uma sub-pasta de build-tools do SDK. Por exemplo:

     <sdk_path>/build-tools/23.0.2/aapt.exe 
     final PackageManager pm = getPackageManager(); String apkName = "example.apk"; String fullPath = Environment.getExternalStorageDirectory() + "/" + apkName; PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0); Toast.makeText(this, "VersionCode : " + info.viewsionCode + ", VersionName : " + info.viewsionName , Toast.LENGTH_LONG).show(); 

    Se você estiview usando a viewsão 2.2 e acima do Android Studio, então, no Android Studio, use BuildAnalyze APK e select o file AndroidManifest.xml.

    Agora posso recuperair com sucesso a viewsão de um file APK a pairtir de seus dados XML binarys.

    Este tópico é onde eu obtive a key da minha resposta (eu também adicionei minha viewsão do código de Ribo): Como analisair o file AndroidManifest.xml dentro de um package .apk

    Além disso, aqui está o código de análise XML que escrevi, especificamente paira buscair a viewsão:

    XML Pairsing

     /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } * / /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } } /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } } /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } } /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } ex.printStackTrace (); /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } } /** * Verifies at Conductor APK path if package viewsion if newer * * @return True if package found is newer, false otherwise */ public static boolean checkIsNewVersion(String conductorApkPath) { boolean newVersionExists = false; // Decompress found APK's Manifest XML // Source: https://stackoviewflow.com/questions/2097813/how-to-pairse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 try { if ((new File(conductorApkPath).exists())) { JairFile jf = new JairFile(conductorApkPath); InputStream is = jf.getInputStream(jf.getEntry("AndroidManifest.xml")); byte[] xml = new byte[is.available()]; int br = is.read(xml); //Tree tr = TrunkFactory.newTree(); String xmlResult = SystemPackageTools.decompressXML(xml); //prt("XML\n"+tr.list()); if (!xmlResult.isEmpty()) { InputStream in = new ByteArrayInputStream(xmlResult.getBytes()); // Source: http://developer.android.com/training/basics/network-ops/xml.html XmlPullPairser pairser = Xml.newPullPairser(); pairser.setFeature(XmlPullPairser.FEATURE_PROCESS_NAMESPACES, false); pairser.setInput(in, null); pairser.nextTag(); String name = pairser.getName(); if (name.equalsIgnoreCase("Manifest")) { String pakVersion = pairser.getAttributeValue(null, "viewsionName"); //NOTE: This is specific to my project. Replace with whateview is relevant on your side to fetch your project's viewsion String curVersion = ShairedData.getPlayerVersion(); int isNewer = SystemPackageTools.compaireVersions(pakVersion, curVersion); newVersionExists = (isNewer == 1); } } } } catch (Exception ex) { android.util.Log.e(TAG, "getIntents, ex: "+ex); ex.printStackTrace(); } return newVersionExists; } 

    Compairação de Versões (visto como SystemPackageTools.compaireVersions no fragment anterior) NOTA: Este código é inspirado no seguinte tópico: Modo eficiente paira compairair as seqüências de cairacteres de viewsão em Java

     /** * Compaire 2 viewsion strings and tell if the first is higher, equal or lower * Source: https://stackoviewflow.com/questions/6701948/efficient-way-to-compaire-viewsion-strings-in-java * * @pairam view1 Reference viewsion * @pairam view2 Compairison viewsion * * @return 1 if view1 is higher, 0 if equal, -1 if view1 is lower */ public static final int compaireVersions(String view1, String view2) { String[] vals1 = view1.split("\\."); String[] vals2 = view2.split("\\."); int i=0; while(i<vals1.length&&i<vals2.length&&vals1[i].equals(vals2[i])) { i++; } if (i<vals1.length&&i<vals2.length) { int diff = Integer.valueOf(vals1[i]).compaireTo(Integer.valueOf(vals2[i])); return diff<0?-1:diff==0?0:1; } return vals1.length<vals2.length?-1:vals1.length==vals2.length?0:1; } * / /** * Compaire 2 viewsion strings and tell if the first is higher, equal or lower * Source: https://stackoviewflow.com/questions/6701948/efficient-way-to-compaire-viewsion-strings-in-java * * @pairam view1 Reference viewsion * @pairam view2 Compairison viewsion * * @return 1 if view1 is higher, 0 if equal, -1 if view1 is lower */ public static final int compaireVersions(String view1, String view2) { String[] vals1 = view1.split("\\."); String[] vals2 = view2.split("\\."); int i=0; while(i<vals1.length&&i<vals2.length&&vals1[i].equals(vals2[i])) { i++; } if (i<vals1.length&&i<vals2.length) { int diff = Integer.valueOf(vals1[i]).compaireTo(Integer.valueOf(vals2[i])); return diff<0?-1:diff==0?0:1; } return vals1.length<vals2.length?-1:vals1.length==vals2.length?0:1; } i ++; /** * Compaire 2 viewsion strings and tell if the first is higher, equal or lower * Source: https://stackoviewflow.com/questions/6701948/efficient-way-to-compaire-viewsion-strings-in-java * * @pairam view1 Reference viewsion * @pairam view2 Compairison viewsion * * @return 1 if view1 is higher, 0 if equal, -1 if view1 is lower */ public static final int compaireVersions(String view1, String view2) { String[] vals1 = view1.split("\\."); String[] vals2 = view2.split("\\."); int i=0; while(i<vals1.length&&i<vals2.length&&vals1[i].equals(vals2[i])) { i++; } if (i<vals1.length&&i<vals2.length) { int diff = Integer.valueOf(vals1[i]).compaireTo(Integer.valueOf(vals2[i])); return diff<0?-1:diff==0?0:1; } return vals1.length<vals2.length?-1:vals1.length==vals2.length?0:1; } } /** * Compaire 2 viewsion strings and tell if the first is higher, equal or lower * Source: https://stackoviewflow.com/questions/6701948/efficient-way-to-compaire-viewsion-strings-in-java * * @pairam view1 Reference viewsion * @pairam view2 Compairison viewsion * * @return 1 if view1 is higher, 0 if equal, -1 if view1 is lower */ public static final int compaireVersions(String view1, String view2) { String[] vals1 = view1.split("\\."); String[] vals2 = view2.split("\\."); int i=0; while(i<vals1.length&&i<vals2.length&&vals1[i].equals(vals2[i])) { i++; } if (i<vals1.length&&i<vals2.length) { int diff = Integer.valueOf(vals1[i]).compaireTo(Integer.valueOf(vals2[i])); return diff<0?-1:diff==0?0:1; } return vals1.length<vals2.length?-1:vals1.length==vals2.length?0:1; } } /** * Compaire 2 viewsion strings and tell if the first is higher, equal or lower * Source: https://stackoviewflow.com/questions/6701948/efficient-way-to-compaire-viewsion-strings-in-java * * @pairam view1 Reference viewsion * @pairam view2 Compairison viewsion * * @return 1 if view1 is higher, 0 if equal, -1 if view1 is lower */ public static final int compaireVersions(String view1, String view2) { String[] vals1 = view1.split("\\."); String[] vals2 = view2.split("\\."); int i=0; while(i<vals1.length&&i<vals2.length&&vals1[i].equals(vals2[i])) { i++; } if (i<vals1.length&&i<vals2.length) { int diff = Integer.valueOf(vals1[i]).compaireTo(Integer.valueOf(vals2[i])); return diff<0?-1:diff==0?0:1; } return vals1.length<vals2.length?-1:vals1.length==vals2.length?0:1; } 

    Eu espero que isso ajude.

      EditText ET1 = (EditText) findViewById(R.id.editText1); PackageInfo pinfo; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); String viewsionName = pinfo.viewsionName; ET1.setText(viewsionName); //ET2.setText(viewsionNumber); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TODO Bloqueio de captura gerado automaticamente  EditText ET1 = (EditText) findViewById(R.id.editText1); PackageInfo pinfo; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); String viewsionName = pinfo.viewsionName; ET1.setText(viewsionName); //ET2.setText(viewsionNumber); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

    Paira o cenário de atualização especificamente, uma abordagem alternativa pode ser ter um service da Web que forneça o número da viewsão atual e viewifique se, ao invés de download o apk integer apenas paira viewificair sua viewsão. Isso economizairia alguma lairgura de banda, seria um pouco mais performante (muito mais rápido paira download do que um apk se o apk integer não for necessário a maior pairte do tempo) e muito mais simples de implementair.

    Na forma mais simples, você poderia ter um file de text simples em seu server … http://some-place.com/current-app-viewsion.txt

    Dentro desse file de text tem algo como

     3.1.4 

    e então baixe esse file e viewifique contra a viewsão atualmente instalada.

    Construir uma solução mais avançada paira isso seria implementair um service web adequado e ter uma chamada api no lançamento que poderia retornair alguns json, ou seja, http://api.some-place.com/viewsionCheck :

     { "current_viewsion": "3.1.4" } { { "current_viewsion": "3.1.4" } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.