Amitpatil215 / whatsapp_share

Share text, link, image, files to specific whatsapp contact in flutter
https://pub.dev/packages/whatsapp_share
MIT License
9 stars 16 forks source link

Android 11 file is not sharing issue #17

Closed venky9885 closed 10 months ago

venky9885 commented 10 months ago

Many users reported from 5 days that file is not sharing in android 11 please solve it ASAp

debmezz commented 10 months ago

I'm having this issue with the share files

W/Bundle (16385): Key android.intent.extra.TEXT expected ArrayList but value was a java.lang.String. The default value was returned. W/Bundle (16385): Attempt to cast generated internal exception: W/Bundle (16385): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList W/Bundle (16385): at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1343) W/Bundle (16385): at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1146) W/Bundle (16385): at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:8620) W/Bundle (16385): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:11626) W/Bundle (16385): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1741) W/Bundle (16385): at android.app.ContextImpl.startActivity(ContextImpl.java:1085) W/Bundle (16385): at android.app.ContextImpl.startActivity(ContextImpl.java:1056) W/Bundle (16385): at android.content.ContextWrapper.startActivity(ContextWrapper.java:411) W/Bundle (16385): at com.example.whatsapp_share.WhatsappShare.shareFile(WhatsappShare.java:218) W/Bundle (16385): at com.example.whatsapp_share.WhatsappShare.onMethodCall(WhatsappShare.java:60) W/Bundle (16385): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) W/Bundle (16385): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) W/Bundle (16385): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) W/Bundle (16385): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) W/Bundle (16385): at android.os.Handler.handleCallback(Handler.java:938) W/Bundle (16385): at android.os.Handler.dispatchMessage(Handler.java:99) W/Bundle (16385): at android.os.Looper.loopOnce(Looper.java:201) W/Bundle (16385): at android.os.Looper.loop(Looper.java:288) W/Bundle (16385): at android.app.ActivityThread.main(ActivityThread.java:7839) W/Bundle (16385): at java.lang.reflect.Method.invoke(Native Method) W/Bundle (16385): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) W/Bundle (16385): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) E/ (16385): FlutterShare: Error

Captura de tela 2023-09-05 164216

bayramaliunuvar commented 10 months ago

I'm having the same problem too Exception has occurred. PlatformException (PlatformException(No Activity found to handle Intent { act=android.intent.action.SEND typ=application/pdf flg=0x10000001 pkg=com.whatsapp clip={application/pdf {T(19)}} (has extras) }, null, null, null))

Amitpatil215 commented 10 months ago

Hello @bayramaliunuvar , @debmezz , @venky9885

Please upgrade whatsapp_share package to 2.0.2 and let me know if it fixes the issue.

dependencies:
  whatsapp_share: ^2.0.2
bayramaliunuvar commented 10 months ago

The problem still persists, my friend.

I used the screenshot sharing code in the sample codes and it gives the following error. Ekran görüntüsü 2023-09-11 095307

Amitpatil215 commented 10 months ago

Hey @bayramaliunuvar Can you try this function?

  Future<void> shareScreenShot() async {
    Directory? directory;
    if (Platform.isAndroid) {
      directory = await getExternalStorageDirectory();
    } else {
      return;
    }

    final String? localPath =
        await _controller.captureAndSave(directory!.path);

    await Future.delayed(const Duration(seconds: 1));
    if (localPath == null) {
      log("localPath is null");
      return;
    }

    await WhatsappShare.shareFile(
      phone: '911234567890',
      filePath: [localPath!],
    );
  }
  1. also verify you have done the required setup https://pub.dev/packages/whatsapp_share#android
  2. and have WhatsApp installed in the test device.
bayramaliunuvar commented 10 months ago

I found the problem, Whatsapp is not installed on my phone. Whatsapp business installed. For this reason, I was able to run it with the following code. Mandatory WhatsApp package needs to be specified

await WhatsappShare.shareFile( phone: FastMethods().whatsAopIcinTelDuzelt( _telNoController.text), filePath: [pdfPath], package: Package.businessWhatsapp);

Amitpatil215 commented 10 months ago

If WhatsApp package not specified, default WhatsApp is used.

For more reliability, consider checking is WhatsApp or Business WhatsApp is installed in user's device or not.

Future<void> isInstalled() async {
    final val = await WhatsappShare.isInstalled(
      package: Package.businessWhatsapp
    );
    print('Whatsapp Business is installed: $val');
  }

Closing this issue! Feel free to comment otherwise.