-2

Android 语音邮件合同代码:

  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();
        }
    }
}

它总是向我显示 0 个语音邮件,我也想集成谷歌语音邮件,提前谢谢

4

1 回答 1

0

对我有用的代码:

    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();
    }

我只需要更改内容uri,但仍然间接相同,但它也对我有用,您也可以参考android sdk中“VoicemailProviderDemo”的示例项目

注意:此代码仅适用于 android 4.0+

于 2012-11-27T22:18:39.303 回答