发送消息到特定号码(WhatsApp的)发送消息、号码、WhatsApp

2023-09-07 03:08:15 作者:年年亦如此

我试过this它似乎是工作适合所有人,但不适合我。如果你想额外的信息告诉我,我会添加它。

I've tried this it seems to be working for everyone but not for me. If you want to extra information inform me and i'll add it.

我的code:

import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.ActionBarSherlock.OnCreateOptionsMenuListener;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuInflater;

public class MainActivity extends SherlockActivity {

我得到的的方法getSherlockActivity()是未定义的类型新View.OnClickListener(){} 此code:

Cursor c = getSherlockActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
                    new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?",
                        new String[] { "96XXXXXXX@s.whatsapp.net" }, null);
                c.moveToFirst();
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));

                startActivity(i);
                c.close();

先谢谢了。

推荐答案

只要改变 getSherlockActivity 这个关键字和您code将正常工作。然而,它只会打开WhatsApp的聊天窗口,并不会自动发送该邮件。

Just change getSherlockActivity to this keyword and you code will work fine. However it will only open whatsapp chat window and not send the message automatically.