【问题标题】:How to share a video from whatsapp to my application如何将视频从 whatsapp 分享到我的应用程序
【发布时间】:2018-07-26 04:12:35
【问题描述】:

如何将视频从 Whatsapp 分享到其他应用程序

遵循清单代码

<activity
            android:name=".Vdo_PostActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.Design.NoActionBar" >

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <data android:mimeType="video/*" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
    </activity>

【问题讨论】:

    标签: video share


    【解决方案1】:

    我有办法

    VdoPostActivity.java

    oncreate(Bundle b){
        Intent receivedIntent = getIntent();
            String receivedAction = receivedIntent.getAction();
            String receivedType = receivedIntent.getType();
    
    ...
    
        if(receivedAction!=null){
                    if(receivedAction.equals(Intent.ACTION_SEND)){
                        //content is being shared
                        if(receivedType.startsWith("text/")){
                            //handle sent text
                        }
                        else if(receivedType.startsWith("video/")){
                            //handle sent image
                            Uri receivedUri = (Uri)receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
                           String  filename=getFileName(receivedUri);
    
    
                            if (receivedUri != null) {
    
                                String datas = null;
                                try {
                                   // uri = getFilePath(this, receivedUri);
                                  String uri=getFilePathFromUri(this,receivedUri);
    
                                    System.out.println("Uri-------------------------------->"+uri);
    
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
    
    }
    
    
    
     private String getFilePathFromUri(Context context, Uri contentUri) {
        FileOutputStream out = null;
        String fileName = getFileNames(contentUri);
        if (!TextUtils.isEmpty(fileName)) {
            File copyFile = new File(TEMP_DIR_PATH + File.separator + fileName);
    
            try {
                File folder = new File(TEMP_DIR_PATH);
                if (!folder.exists())
                    folder.mkdirs();
    
                File mypath = new File(folder, "VID_" + System.currentTimeMillis() + ".mp4");
    
                out = new FileOutputStream(mypath);
            }
            catch (Exception e){
                System.out.println("Error Mobe--------------------------------->"+e);
            }
    
            finally {
                try {
                    if (out != null)
                        out.close();
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            copy(context, contentUri, copyFile);
            return copyFile.getAbsolutePath();
        }
        return null;
    }
    
    private void copy(Context context, Uri srcUri, File dstFile) {
    
    
        try {
            InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
            if (inputStream == null) return;
            OutputStream outputStream = new FileOutputStream(dstFile);
            IOUtils.copy(inputStream, outputStream);
            inputStream.close();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private String getFileNames(Uri uri) {
    
        if (uri == null) return null;
        String fileName = null;
        String path = uri.getPath();
        int cut = path.lastIndexOf('/');
        if (cut != -1) {
            fileName = path.substring(cut + 1);
        }
        return fileName;
    }
    

    【讨论】:

    • 将视频从 whatsapp 分享到其他应用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2012-10-08
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    相关资源
    最近更新 更多