Question

Android VoiceMailContract Code :

  public void voiceMail(Context ctx) {
    if (Build.VERSION.SDK_INT >= 14) {
        try {
            final String selection = VoicemailContract.Voicemails.IS_READ + "=0";
            final String sortOrder = VoicemailContract.Voicemails.DATE + " DESC";
            String uri = VoicemailContract.Voicemails.CONTENT_URI + "?"
                    + VoicemailContract.PARAM_KEY_SOURCE_PACKAGE + "="
                    + getPackageName();
            Cursor cursor = ctx.getContentResolver().query(Uri.parse(uri), null,
                    selection, null, sortOrder);
            TextView tv = (TextView)findViewById(R.id.textView1);
            tv.setText("You have "+cursor.getCount()+" voice mail");
            cursor.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

it's always showing me 0 voice mail and i also want to integrate google voice mail, Thanks in advance

Was it helpful?

Solution

Usefull code to me:

    Cursor cursor = null;
    try {
        cursor = mContentResolver.query(mBaseUri, FULL_PROJECTION,
                filter != null ? filter.getWhereClause() : null,
                null, getSortBy(sortColumn, sortOrder));
        while (cursor.moveToNext()) {
            // A performance optimisation is possible here.
            // The helper method extracts the column indices once every time it is called,
            // whilst
            // we could extract them all up front (without the benefit of the re-use of the
            // helper
            // method code).
            // At the moment I'm pretty sure the benefits outweigh the costs, so leaving as-is.
        }
        Log.v(TAG,"Unread Voicemails:"+cursot.getCount());
        return results;
    } finally {
        cursor.close();
    }

I need to change only content uri but still both are same indirectly but then also it's work for me, and you can also refer sample project of "VoicemailProviderDemo" in android sdk

NOTE: this code is only work in android 4.0+

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top