Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio and Video share empty value problem #199

Open
mnuriyumusak opened this issue Dec 27, 2019 · 5 comments
Open

Audio and Video share empty value problem #199

mnuriyumusak opened this issue Dec 27, 2019 · 5 comments

Comments

@mnuriyumusak
Copy link

When I try to share ogg, mp3 or mpeg file type comes correct but value is empty. Why value is empty. It is not happening when I share text or image files.

@Pzz0912
Copy link

Pzz0912 commented Jan 16, 2020

Same, have you solved it?

@mnuriyumusak
Copy link
Author

Same, have you solved it?

I have solved just the "sharing ogg file" part. However, it is very specific solution. I edit the code actually I have added new lines to the this library for my need. I do not know if my solution suits you or not? Normally this library returns the uri of the file, however, my code returns bytes of the voice file that is shared.

@flo-wolf
Copy link

Same, have you solved it?

I have solved just the "sharing ogg file" part. However, it is very specific solution. I edit the code actually I have added new lines to the this library for my need. I do not know if my solution suits you or not? Normally this library returns the uri of the file, however, my code returns bytes of the voice file that is shared.

Would you be so kind and share your solution?

@mnuriyumusak
Copy link
Author

mnuriyumusak commented Feb 22, 2020

Same, have you solved it?

I have solved just the "sharing ogg file" part. However, it is very specific solution. I edit the code actually I have added new lines to the this library for my need. I do not know if my solution suits you or not? Normally this library returns the uri of the file, however, my code returns bytes of the voice file that is shared.

Would you be so kind and share your solution?

node_modulers -> react-native-share-extension -> android -> src -> main -> java -> com -> alinz -> parkerdan -> shareextension in this path my ShareModule.java class is below .

In this way, when user shares an ogg voice file, I can get the bytes of the file.

package com.alinz.parkerdan.shareextension;

import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.net.Uri;

import android.graphics.Bitmap;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import android.util.Base64;
import android.content.Context;
import android.content.ContentResolver;

public class ShareModule extends ReactContextBaseJavaModule {


  public ShareModule(ReactApplicationContext reactContext) {
      super(reactContext);
  }

  @Override
  public String getName() {
      return "ReactNativeShareExtension";
  }

  @ReactMethod
  public void close() {
    getCurrentActivity().finish();
  }

  @ReactMethod
  public void data(Promise promise) {
      promise.resolve(processIntent());
  }

  public byte[] getBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];

        int len = 0;
        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }
        return byteBuffer.toByteArray();
    }

  public WritableMap processIntent() {
      WritableMap map = Arguments.createMap();

      String value = "";
      String type = "";
      String action = "";

      Activity currentActivity = getCurrentActivity();

      if (currentActivity != null) {
        Intent intent = currentActivity.getIntent();
        action = intent.getAction();
        type = intent.getType();
        Log.e("typeeeeeee","e"+type);
        if (type == null) {
          type = "";
        }
       if(Intent.ACTION_SEND.equals(action) && "audio/ogg; codecs=opus".equals(type) || "audio/ogg".equals(type)){
           Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            InputStream iStream = null;
            try {
                iStream = currentActivity.getBaseContext().getContentResolver().openInputStream(uri);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            byte[] inputData = new byte[0];
            try {
                inputData = getBytes(iStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
            value = Base64.encodeToString(inputData, Base64.DEFAULT);
       }
       else {
         value = "";
       }
      } else {
        value = "";
        type = "";
      }

      map.putString("type", type);
      map.putString("value",value);

      return map;
  }
}

@ajith-ab
Copy link

i ve used this package with all new features with react native greater than 0.60 support react-native-receive-sharing-intent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants