Android VoiceMailContract代码:
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个语音邮件,我还想整合谷歌语音邮件, 提前致谢
答案 0 :(得分: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 +