Nauman Shafqat
Nauman Shafqat

Reputation: 81

How can i fetch Whatsapp user's status and display in my android app?

I want to fetch live status from Whatsapp into my android activity. Is it possible to do this? If yes your guidance will be really appreciated.

Please see the image i want to make an activity containing all the statuses. Just like the image

Thanks

Upvotes: 8

Views: 12461

Answers (5)

Bhavin Solanki
Bhavin Solanki

Reputation: 510

Problem of path and file not found solved with this.

You can try this Path. it may be helpful for you.

For Android-10 and above

File(Environment.getExternalStorageDirectory() + File.separator + "Android/media/com.whatsapp/WhatsApp/Media/.Statuses")

Below Android-10 Version

File(Environment.getExternalStorageDirectory() + File.separator + "WhatsApp/Media/.Statuses")

Upvotes: 0

ahmad bajwa
ahmad bajwa

Reputation: 1068

There You Go

    final String WHATSAPP_STATUSES_LOCATION = "/WhatsApp/Media/.Statuses";
    RecyclerView mRecyclerViewMediaList = findViewById(R.id.recyclerViewMedia);
    LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
    mRecyclerViewMediaList.setLayoutManager(mLinearLayoutManager);
    ListAdapter recyclerViewMediaAdapter = new ListAdapter(MainActivity.this, this.getListFiles(new File(Environment.getExternalStorageDirectory().toString() + WHATSAPP_STATUSES_LOCATION)));
    mRecyclerViewMediaList.setAdapter(recyclerViewMediaAdapter);



  private ArrayList<File> getListFiles(File parentDir) {
    ArrayList<File> inFiles = new ArrayList<>();
    File[] files;
    files = parentDir.listFiles();
    if (files != null) {
        for (File file : files) {
            Log.e("check", file.getName());
            if (file.getName().endsWith(".jpg") ||
                    file.getName().endsWith(".gif") ||
                    file.getName().endsWith(".mp4")) {
                if (!inFiles.contains(file))
                    inFiles.add(file);
            }
        }
    }
    return inFiles;
}

Adapter

 public class ListAdapter extends RecyclerView.Adapter<ListAdapter.MyViewHolder> {
    final Context context;
    final ArrayList<File> modelFeedArrayList;
    private static final String DIRECTORY_TO_SAVE_MEDIA_NOW = "/WhatsappStatus/";

    public ListAdapter(Context context, final ArrayList<File> modelFeedArrayList) {
        this.context = context;
        this.modelFeedArrayList = modelFeedArrayList;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_media_row_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {

        File currentFile = modelFeedArrayList.get(position);

        if (currentFile.getAbsolutePath().endsWith(".mp4")) {
            holder.cardViewImageMedia.setVisibility(View.GONE);
            holder.cardViewVideoMedia.setVisibility(View.VISIBLE);
            Uri video = Uri.parse(currentFile.getAbsolutePath());
            holder.videoViewVideoMedia.setVideoURI(video);
            holder.videoViewVideoMedia.setOnPreparedListener(mp -> {
                mp.setLooping(true);
                holder.videoViewVideoMedia.start();
            });
        } else {
            holder.cardViewImageMedia.setVisibility(View.VISIBLE);
            holder.cardViewVideoMedia.setVisibility(View.GONE);
            Bitmap myBitmap = BitmapFactory.decodeFile(currentFile.getAbsolutePath());
            holder.imageViewImageMedia.setImageBitmap(myBitmap);
        }
    }


    @Override
    public int getItemCount() {
        return modelFeedArrayList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView imageViewImageMedia;
        VideoView videoViewVideoMedia;
        CardView cardViewVideoMedia;
        CardView cardViewImageMedia;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageViewImageMedia = itemView.findViewById(R.id.imageViewImageMedia);
            videoViewVideoMedia = itemView.findViewById(R.id.videoViewVideoMedia);
            cardViewVideoMedia = itemView.findViewById(R.id.cardViewVideoMedia);
            cardViewImageMedia = itemView.findViewById(R.id.cardViewImageMedia);

        }
    }
}

Row XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_margin="10dp">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardViewVideoMedia"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:visibility="gone">
        <VideoView
            android:id="@+id/videoViewVideoMedia"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

    </androidx.cardview.widget.CardView>


    <androidx.cardview.widget.CardView
        android:id="@+id/cardViewImageMedia"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

        <ImageView
            android:id="@+id/imageViewImageMedia"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:contentDescription="@string/todo" />


    </androidx.cardview.widget.CardView>


</RelativeLayout>

add to your AndroidManifest.xml.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />



 <application
        android:requestLegacyExternalStorage="true"

Android 10 File.listFiles() may return null, see File exists and IS directory, but listFiles() returns null

Upvotes: 2

Tarif Chakder
Tarif Chakder

Reputation: 1856

For Kotlin Lover

   companion object {
    const val WHATSAPP_STATUS_FOLDER_PATH = "/WhatsApp/Media/.Statuses/"
   }

   fun getImagePath(): ArrayList<String> {
    // image path list
    val list: ArrayList<String> = ArrayList()

    // fetching file path from storage
    val file = File(Environment.getExternalStorageDirectory().toString() + WHATSAPP_STATUS_FOLDER_PATH)
    val listFile = file.listFiles()

    if (listFile != null && listFile.isNullOrEmpty()) {
        Arrays.sort(listFile, LastModifiedFileComparator.LASTMODIFIED_REVERSE)
    }

    if (listFile != null) {
        for (imgFile in listFile) {
            if (
                imgFile.name.endsWith(".jpg")
                || imgFile.name.endsWith(".jpeg")
                || imgFile.name.endsWith(".png")
            ) {
                val model = imgFile.absolutePath
                list.add(model)
            }
        }
    }

    // return imgPath List
    return list
}

Upvotes: 4

RVK
RVK

Reputation: 67

WhatsApp store showed status to your device memory or sd card WhatsApp/Media/.Statuses folder. This folder is hidden. You can fetch data from there.

Upvotes: 6

Woods
Woods

Reputation: 101

Well all the content of WhatsApp user status are locally stored in /WhatsApp/.Statuses folder except text Statuses. You can simply load all the images and videos that are in the folder in grid view and give options to save and share.

Upvotes: 1

Related Questions