通过我的应用程序在应用程序特定号码中发送消息

时间:2015-02-24 05:17:21

标签: android android-intent social-networking sharing whatsapp

Hello Friends我想在我的java文件中用我定义的app特定号码发送消息。我按照这个link并在我的项目中包含以下代码。

public void sendWhatsAppMessageTo(String whatsappid) {

 Cursor c = getSherlockActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
    new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?",
    new String[] { whatsappid }, null);
c.moveToFirst();

Intent whatsapp = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
c.close();

if (whatsapp != null) {

startActivity(whatsapp);      

} else {
    Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
            .show();
//download for example after dialog
            Uri uri = Uri.parse("market://details?id=com.whatsapp");
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
}

}

并抛出cursorindexoutofboundexception:请求索引0,大小为0.请帮我解决这个问题

0 个答案:

没有答案