7
votes

Envoi de fichier APK Android

J'utilise ce code pour envoyer le fichier APK de l'application sur un autre périphérique. Cela fonctionne sur Android 2.3.3, mais ne fonctionne pas sur Android 4 +.

Où est le problème? P>

J'ai enregistré le getpackagecodepath () code> et il renvoie le Fichier APK sur Android 4+, mais tout le code ne fonctionne pas, et lorsque Bluetooth démarre, il n'enverse rien. P>

ArrayList<Uri> uris = new ArrayList<Uri>();
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("application/vnd.android.package-archive");
uris.add(Uri.parse(getApplication().getPackageCodePath()));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));


7 commentaires

Êtes-vous sûr que votre appareil Android 4.0 est équipé pour gérer les transferts Bluetooth? Avez-vous essayé d'envoyer un fichier sur Bluetooth en utilisant un gestionnaire de fichiers OI ou quelque chose?


Oui, et je peux envoyer un fichier via mon téléphone avec les gestionnaires de fichiers


@Ata Avez-vous eu une réponse?


Nope, il semble que l'opération Android 4 bloquée sur le fichier Accessign sur les fichiers APK d'origine


ce n'est pas bloqué, mais cela a changé. Voir gettaplicationInfo (). Publicsourcedir


getApplicationInfo (). Publicsourcedir


Envoyez-vous APK dans votre application?


6 Réponses :


1
votes

Modifier la ligne: xxx

à xxx

et il devrait fonctionner dans tous les périphériques 4.x. Sinon, vous pouvez également faire quelque chose comme ceci: xxx

Les deux des manières ci-dessus fonctionnent pour moi.


0 commentaires

0
votes

Vous pouvez utiliser gettaplicationinfo (). Publicsourcedir au lieu de gettaplication (). getpackagecodepath () Pour obtenir le chemin d'accès à l'APK de votre application, puis utilisez-le dans un Action_send Intention Pour envoyer le fichier via Bluetooth.

vérifier ici pour un exemple: Transfert de fichier Bluetooth sur Android (même des types restreints)


0 commentaires

13
votes

J'utilise ci-dessous le code pour envoyer APK. et ça marche xxx


1 commentaires

+1 J'ai essayé ce code, cela fonctionne dans les appareils Samsung mais ne travaille pas sur Moto G2. S'il vous plaît laissez-moi savoir comment trier le problème



0
votes
InputStream in = null;
            OutputStream out = null;
            File apkPublicFilePath = new File(
                    Environment
                            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                    "myapk.apk");
            try {

                in = getResources().openRawResource(R.raw.myapk);
                out = new FileOutputStream(apkPublicFilePath);
                byte[] buffer = new byte[1024];
                int length;
                while ((length = in.read(buffer)) > 0) {
                    out.write(buffer, 0, length);
                }

                // Close the streams
                out.flush();
                out.close();
                in.close();
            } catch (IOException e) {
                Log.d(TAG, "Error in copy files");
            }

            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_STREAM,

            Uri.fromFile(apkPublicFilePath.getAbsoluteFile()));
            try {
                sendIntent.setType("application/vnd.android.package-archive");
                startActivity(Intent.createChooser(
                        sendIntent,
                        PersianReshape.reshape(getResources().getString(
                                R.string.msg_send))));
            } catch (Exception e) {
                sendIntent.setType("*/*");
                startActivity(Intent.createChooser(
                        sendIntent,
                        PersianReshape.reshape(getResources().getString(
                                R.string.msg_send))));
            }

0 commentaires

0
votes

J'espère que cela fonctionne:

// Get current ApplicationInfo to find .apk path
ApplicationInfo app = getApplicationContext().getApplicationInfo();
String filePath = app.sourceDir;

Intent intent = new Intent(Intent.ACTION_SEND);

// MIME of .apk is "application/vnd.android.package-archive".
// but Bluetooth does not accept this. Let's use "*/*" instead.
intent.setType("*/*");

// Only use Bluetooth to send .apk
intent.setPackage("com.android.bluetooth");

// Append file and send Intent
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
startActivity(Intent.createChooser(intent, "Share app"));


0 commentaires

0
votes
ArrayList<Uri> uris = new ArrayList<Uri>();
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("*/*");
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir)));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));
Use / this worked for me

0 commentaires