2016-12-01 2 views
1

J'ai un chemin de fichier vidéo et je souhaite partager la vidéo sur les médias sociaux, mais je n'arrive pas à partager la vidéo. J'essaie le code suivant dans Android Studio 2.2, mais cela ne fonctionne pas.Android: l'intention de partage ne fonctionne pas pour le chemin d'accès du fichier vidéo

Extrait de code:

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button shareBtn = (Button) findViewById(R.id.sharebutton); 

    shareBtn .setOnClickListener(
      new Button.OnClickListener() { 
       public void onClick(View v) { 

        File f = new File("/sdcard/VID_20161201123613.mp4"); 
        Uri uriPath = Uri.parse(f.getPath()); 

        Intent shareIntent = new Intent(); 
        shareIntent.setAction(Intent.ACTION_SEND); 
        shareIntent.putExtra(Intent.EXTRA_TEXT, "Text");     
        shareIntent.putExtra(Intent.EXTRA_STREAM, uriPath); 
        shareIntent.setType("video/*"); 
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
        startActivity(Intent.createChooser(shareIntent, "send")); 

       } 
      } 
    ); 
} 
+0

U vouloir montrer la liste à partager –

Répondre

1

Essayez ceci:

public void shareVideo(final String title, String path) { 

MediaScannerConnection.scanFile(getActivity(), new String[] { path }, 

      null, new MediaScannerConnection.OnScanCompletedListener() { 
       public void onScanCompleted(String path, Uri uri) { 
        Intent shareIntent = new Intent(
          android.content.Intent.ACTION_SEND); 
        shareIntent.setType("video/*"); 
        shareIntent.putExtra(
          android.content.Intent.EXTRA_SUBJECT, title); 
        shareIntent.putExtra(
          android.content.Intent.EXTRA_TITLE, title); 
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
        shareIntent 
          .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 
        context.startActivity(Intent.createChooser(shareIntent, 
          getString(R.string.str_share_this_video))); 

       } 
      }); 
} 
+1

Il donne une erreur lors du partage sur WhatsApp - Le format de fichier n'est pas supporté et pour Gmail - Impossible de joindre emp fichier ty. – SRK

+0

quel type de vidéo souhaitez-vous partager? –

+0

http://www.androidcode.ninja/android-share-intent-example/ vérifier ce lien c'est exactement ce que vous voulez –

1

utiliser ce code pour choisir une vidéo de la carte SD, puis envoyez un email avec la vidéo ....

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
    sendIntent.setType("video/3gp"); 
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Video"); 
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/dcim/Camera/filename.3gp")); 
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the Video"); 
    startActivity(Intent.createChooser(sendIntent, "Email:"));