Sending message to specific Number(Whatsapp)

℡╲_俬逩灬. 提交于 2019-12-08 09:35:02

问题


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.

My 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 {

I get The method getSherlockActivity() is undefined for the type new View.OnClickListener(){} From this 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();

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/18548173/sending-message-to-specific-numberwhatsapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!