I'm trying to open a particular whatsapp group through my app using intents, but unfortunately the app crashes everytime

13 Views Asked by At

This is my code to perform the same function.

private void sendGroupMessage(String string) {

        String shareBody = string;

        
        String groupChatId = "J30MeqEdBJl1a3fQYsJVmB";

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, shareBody);
        intent.setPackage("com.whatsapp");

        // Construct the group chat URI
        String groupChatUri = "https://chat.whatsapp.com/" + groupChatId;
        intent.setData(Uri.parse(groupChatUri));

        // Check if WhatsApp is installed
        if (intent.resolveActivity(getPackageManager()) == null) {
            Toast.makeText(this, "Please install WhatsApp first.", Toast.LENGTH_SHORT).show();
            return;
        }

        // Start WhatsApp with the specified group chat
        startActivity(intent);
    }

Here's my logcat, which says there is no app present to perform this activity. FATAL EXCEPTION: main Process: com.example.opshiva, PID: 25752 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 pkg=com.whatsapp clip={null {T(19)}} (has extras) } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2187) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1831) at android.app.Activity.startActivityForResult(Activity.java:5580) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:780) at android.app.Activity.startActivityForResult(Activity.java:5533) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:761) at android.app.Activity.startActivity(Activity.java:6036) at android.app.Activity.startActivity(Activity.java:6003) at com.example.opshiva.MainActivity.sendGroupMessage(MainActivity.java:361) at com.example.opshiva.MainActivity.access$200(MainActivity.java:32) at com.example.opshiva.MainActivity$2.onClick(MainActivity.java:151) at android.view.View.performClick(View.java:7570) at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1218) at android.view.View.performClickInternal(View.java:7540) at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) at android.view.View$PerformClick.run(View.java:29710) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:240) at android.os.Looper.loop(Looper.java:351) at android.app.ActivityThread.main(ActivityThread.java:8423) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

Please tell me where am i going wrong.

0

There are 0 best solutions below