简体   繁体   English

如何获取 Whatsapp 用户的状态并在我的 android 应用程序中显示?

[英]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.我想从 Whatsapp 获取实时状态到我的 android 活动中。 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谢谢

WhatsApp store showed status to your device memory or sd card WhatsApp/Media/.Statuses folder. WhatsApp 商店向您的设备内存或 SD 卡WhatsApp/Media/.Statuses文件夹显示状态。 This folder is hidden.这个文件夹是隐藏的。 You can fetch data from there.您可以从那里获取数据。

For Kotlin Lover对于 Kotlin 爱好者

   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
}

Well all the content of WhatsApp user status are locally stored in /WhatsApp/.Statuses folder except text Statuses.好吧,除了文本状态之外,WhatsApp 用户状态的所有内容都存储在/WhatsApp/.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.您只需在网格视图中加载文件夹中的所有图像和视频,并提供保存和共享选项。

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行 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.添加到您的 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 Android 10 File.listFiles() 可能返回 null,请参阅文件存在和 IS 目录,但 listFiles() 返回 null

Problem of path and file not found solved with this. file not found path文件的问题由此解决。

You can try this Path.你可以试试这个路径。 it may be helpful for you.它可能对你有帮助。

For Android-10 and above适用于Android-10及更高版本

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

Below Android-10 Version Android-10版本以下

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从我的 Android 应用程序通过 WhatsApp 向特定联系人发送消息? - How can I send message to specific contact through WhatsApp from my android app? 如何将音频文件从我的应用程序发送到 Whatsapp? - How can I send audio files from my app to Whatsapp? 如何每天在我的android应用中显示文本 - How can I display a text perday in my android app 如何在我的 Android 应用程序中使用用户自己的短信服务发送 OTP 并进行手机号码验证? - How can I use a user's own SMS service to send OTP and make mobile number verification in my Android app? 我无法从我的应用程序将视频分享到whatsapp - I can not share video to whatsapp from my app 如何从WhatsApp到Android中的我的应用程序获取pdf文件数据? - How to get pdf file data from whatsapp to my app in android? Android:当我在Sql Server中将状态更改为false时,如何从应用程序自动注销? - Android : How can i Auto Log out from my app when i change my status to false in Sql server? 如何按大多数用户的位置顺序显示我的列表 (RecyclerView)? - How can I display my list (RecyclerView) in order of the most user's location? 如何让我的程序在 JtextField 中显示数据库中的用户名? - How can I make my program display the user's name from the database in JtextField? 如何将我的应用用户转移到Android应用中的下一个级别 - How can I move my app user to next level in android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM