2012-11-27 57 views
-2

的Android VoiceMailContract代碼:的Android 4.0+ 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語音郵件,我也希望整合谷歌語音郵件, 在此先感謝

+1

純代碼編寫工作的要求是題外話上堆棧溢出(你至少可以抽出時間寫一個完整的句子)。 – assylias

回答

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」 FER示例項目

注:此代碼僅在Android 4.0以上版本