Showing posts with label whatsapp sens message. Show all posts
Showing posts with label whatsapp sens message. Show all posts

Tuesday, October 5, 2021

Whatsapp send in Android

 àWhatsapp Message send:-

Xml code:-

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
tools:context=".MainActivity">

  <
Button
     
android:layout_width="match_parent"
     
android:layout_height="wrap_content"
     
android:id="@+id/btn"
     
android:text="click"
     
android:onClick="open1"/>

</
androidx.constraintlayout.widget.ConstraintLayout>

 

Java code:-

package com.example.message;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

    }
   
public static void open(Context context, String number, String message)
    {
       
try {
            number = number.replace(
"","").replace("+","");
            Intent intent =
new Intent("android.intent.action.MAIN");
            intent.setType(
"text/plan");
            intent.putExtra(Intent.
EXTRA_TEXT,message);
            intent.setComponent(
new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
            intent.putExtra(
"jid", PhoneNumberUtils.stripSeparators(number)+"@s.whatsapp.net");
            context.startActivities(
new Intent[]{intent});

        }
catch (Exception e) {

        }

    }
   
public  void openWhatsAppConversationUsingUri(Context context,String number,String message)
    {
        Uri uri = Uri.parse(
"https://api.whatsapp.com/send?phone="+number+"&text="+message);
        Intent intent =
new Intent(Intent.ACTION_VIEW,uri);
        context.startActivities(
new Intent[]{intent});
    }

   
public void open1(View view) {
        open(MainActivity.
this,"9315146427","hello niranjan");
    }
}

Activity Navigation One Activity to another Activity

Main Activity :-   <? xml version ="1.0" encoding ="utf-8" ?> < RelativeLayout xmlns: android ="http://sch...