2011-06-13 42 views
3

我正在寫一個應用程序,它需要閱讀用戶的短信才能進行基本操作。谷歌表示,短信內容提供商不受支持,可能不會出現在某些手機中,或可能不適用於未來版本的Android。我想知道是否有人知道沒有短信內容提供商的任何特定手機?我知道這個問題已被問到 -任何沒有短信內容提供商的Android手機?

Is there any phone that doesn't have sms inbox content provider?但沒有人提供了答案。 或者,如果有人可以建議使用標準API讀取傳入和傳出郵件的方式,那會更好。

回答

3

我一直沒能找到一個電話沒有(從谷歌搜索至少)短信內容提供商。我不認爲製造商會冒着破壞與衆多SMS應用程序兼容性的風險(這些應用程序都使用此私有API)。 此外,在這一點上似乎沒有標準的方式來訪問傳入和傳出的消息。

更新:這已經作出了公開的API與4.4 - https://developer.android.com/reference/android/provider/Telephony.html

2
Uri mSmsinboxQueryUri = Uri.parse("content://sms"); 
Cursor cursor1 = getContentResolver().query(
     mSmsinboxQueryUri, 
     new String[] { "_id", "thread_id", "address", "person", "date", 
       "body", "type" }, null, null, null); 
startManagingCursor(cursor1); 
String[] columns = new String[] { "address", "person", "date", "body", 
     "type" }; 
if (cursor1.getCount() > 0) { 
    String count = Integer.toString(cursor1.getCount()); 
    Log.e("Count",count); 
    while (cursor1.moveToNext()) { 
     out.write("<message>"); 
     String address = cursor1.getString(cursor1 
       .getColumnIndex(columns[0])); 
     String name = cursor1.getString(cursor1 
       .getColumnIndex(columns[1])); 
     String date = cursor1.getString(cursor1 
       .getColumnIndex(columns[2])); 
     String msg = cursor1.getString(cursor1 
       .getColumnIndex(columns[3])); 
     String type = cursor1.getString(cursor1 
       .getColumnIndex(columns[4])); 
} 
} 

Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox"); 
Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent"); 

使用這個URI u能讀取收件箱以及已發送的郵件。

而且在清單文件中的用戶權限是

<uses-permission android:name="android.permission.READ_SMS" /> 
+1

也許你誤解了我的問題。我想知道是否有人遇到沒有SMS內容提供商的手機,或者是否有標準的「官方」方式訪問收件箱。您的解決方案使用隱藏的API。 – BlueSilver 2011-06-14 18:21:11