我需要Android短信應用程序的幫助。我從我的android應用程序發送消息給手機號碼。我需要檢查消息是否已從我的應用程序中以該移動號碼的INBOX傳送。我需要檢查發送給手機號碼的消息是否已發送。 IE瀏覽器。 Desitnation匹配。如何從android應用程序訪問INBOX消息。請在這個問題上指導我。如果有人幫助我以示例工作爲例,這將非常有幫助。從Android應用程序訪問收件箱消息
在此先感謝。
我需要Android短信應用程序的幫助。我從我的android應用程序發送消息給手機號碼。我需要檢查消息是否已從我的應用程序中以該移動號碼的INBOX傳送。我需要檢查發送給手機號碼的消息是否已發送。 IE瀏覽器。 Desitnation匹配。如何從android應用程序訪問INBOX消息。請在這個問題上指導我。如果有人幫助我以示例工作爲例,這將非常有幫助。從Android應用程序訪問收件箱消息
在此先感謝。
如何從Android應用程序訪問INBOX messagr,答案是低於,
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext())
{
// Retrieve sms
// see column "address" for comparing
// Then update the sms and set the column "read" to 1
}
試試這個
public static final Uri SMS_INBOX_CONTENT_URI = Uri.parse("content://sms/inbox");
Cursor cursor = managedQuery(SMS_INBOX_CONTENT_URI, new String[]{TextSmsColumns.ID, TextSmsColumns.ADDRESS,
TextSmsColumns.DATE, TextSmsColumns.BODY}, null, null, TextSmsColumns.DATE + " DESC");
cursor.moveToFirst();
StringBuilder builder = new StringBuilder();
for(int i = 0 ; i < cursor.getCount(); i++)
{
builder.append(" ID-"+i);
String s= " Address: "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.ADDRESS))
+ " Body: "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.BODY))
+ " Date: "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.DATE));
builder.append(s);
cursor.moveToNext();
}
嘗試這種方式
在AndroidManifest.xml文件,添加如下因素權限:
(android.permission.RECEIVE_SMS
)
(android.permission.SEND_SMS
)
// Demo source code to sends an SMS and notify status
private void send(String number, String message)
{
// notify when the SMS has been sent
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Sent!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "GENERIC_FAILURE!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "RADIO_OFF!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "ERROR_NULL_PDU!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "ERROR_NO_SERVICE!",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter("SMS_SENT"));
// notify when the SMS has been delivered
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg1, Intent arg2) {
switch (getResultCode())
{
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "Not delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter("SMS_DELIVERED"));
PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0,
new Intent("SMS_SENT"), 0);
PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this, 0,
new Intent("SMS_DELIVERED"), 0);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message, sentPendingIntent, deliveredPendingIntent);
}