بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ

گزارش عدم ارسال sms

مدیریت گفتگو
SMS
afr_msb 10 سال پیش
آخرین تغییر: 9 سال پیش

سلام من در ارسال sms مشکلی ندارم مشکل پیغام دلیوری آن است که حتی برای خط خاموش هم ارسال شده میگوید حتی شماره نا معتبر . لطفا راهنمایی کنید . اینم تابع منه

     private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(SMS_Test2Activity.this, 0,
new Intent(SENT), PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent deliveredPI = PendingIntent.getBroadcast(SMS_Test2Activity.this,
0, new Intent(DELIVERED), PendingIntent.FLAG_UPDATE_CURRENT);

// ---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(SMS_Test2Activity.this, "SMS sent",
Toast.LENGTH_SHORT).show();

break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(SMS_Test2Activity.this, "Generic failure",
Toast.LENGTH_SHORT).show();
// print_deliver = 0;
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(SMS_Test2Activity.this, "No service",
Toast.LENGTH_SHORT).show();
// print_deliver = 0;
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(SMS_Test2Activity.this, "Null PDU",
Toast.LENGTH_SHORT).show();
// print_deliver = 0;
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
// print_deliver = 0;
break;

}
}
}, new IntentFilter(SENT));
// ---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {

@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(SMS_Test2Activity.this, "SMS delivered",
Toast.LENGTH_SHORT).show();
send_deliver = 1;
break;
case Activity.RESULT_CANCELED:
Toast.makeText(SMS_Test2Activity.this, "SMS not delivered",
Toast.LENGTH_SHORT).show();
send_deliver = 2;
break;
}
}
}, new IntentFilter(DELIVERED));

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
// Intent smsintent = new Intent(SMS_PostActivity.this, SecondActivity.Activity);
// startActivity(smsintent);
}

نظرات

احمد 10 سال پیش
یعنی برای خط خاموش هم میگه تحویل داده شد؟
afr_msb 10 سال پیش
بله و فیلد مربوطه را در سرور true ارسال میشه
Amir 10 سال پیش
خب نرم افزار پیام رسان پیش فرض خود گوشی هم همینجوریه.
afr_msb 10 سال پیش
وقتی با گوشی پیام ارسال میکنیم روی پیام بزنین قسمت جزئیات مشخص کرده پیام ارسال شده یا نه . سوالم اینه چطور میتونم از امکان گوشی استفاده کنم ؟
احمد 10 سال پیش
برای این باید جزییات پیام را در بیارید که جدول کاملش توی نت هست و ساختار دیتابیسش اگر به نتیجه نرسیدید اعلام کنید
afr_msb 10 سال پیش
نه متاسفانه به نتیجه نرسیدم
afr_msb 10 سال پیش
ای کاش یه نفر بهم میگفت چه کنم . اصلا وارد swich case تابم نمیشه . خیلی حیاتیه کمک کنین
احمد 10 سال پیش
شما جزییات پایم های ارسالی را می خواهی یا فقط گزارش تحویل؟
فرهاد 10 سال پیش
سلام منم توی پروژه ام همچین مشکلی دارم فعلا بیخیالش شدم چون تنها حدسم اینه که شاید توی امولیتور مشکل داره . در این مورد لطفا با بنده در ارتباط باشید.
afr_msb 10 سال پیش
نه من روی گوشی و سرور تست میکنم اصلا جواب نمیده
afr_msb 10 سال پیش
شما هم اگر راه حلشو پیدا کردین خبر کنین
فرهاد 10 سال پیش
بله چشم. نگران نباشید حتما پیدا میکنیم
فرهاد 9 سال پیش
سلام یه پروژه پیدا کردم که کاملا درست کار میکنه و گزارش ارسال اس ام اس و تحویل اس ام اسش درسته
afr_msb 9 سال پیش
ممنون حتما تست میکنم منم راه حلشو پیدا کردم یکم خلوت بشم با توضیح میذارم

پاسخ‌ها 1

فرهاد 9 سال پیش

 package net.learn2develop.SMS;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import android.telephony.SmsManager;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class SMSActivity extends Activity {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI, deliveredPI;
BroadcastReceiver smsSentReceiver, smsDeliveredReceiver;
IntentFilter intentFilter;

private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//�-display the SMS received in the TextView�-
TextView SMSes = (TextView) findViewById(R.id.textView1);
SMSes.setText(intent.getExtras().getString("sms"));
}
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);

deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);

//�-intent to filter for SMS messages received�-
intentFilter = new IntentFilter();
intentFilter.addAction("SMS_RECEIVED_ACTION");

//---register the receiver---
registerReceiver(intentReceiver, intentFilter);
}

@Override
public void onResume() {
super.onResume();

//---register the receiver---
//registerReceiver(intentReceiver, intentFilter);

//---create the BroadcastReceiver when the SMS is sent---
smsSentReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS 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_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
};

//---create the BroadcastReceiver when the SMS is delivered---
smsDeliveredReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
};

//---register the two BroadcastReceivers---
registerReceiver(smsDeliveredReceiver, new IntentFilter(DELIVERED));
registerReceiver(smsSentReceiver, new IntentFilter(SENT));
}

@Override
public void onPause() {
super.onPause();

//---unregister the receiver---
//unregisterReceiver(intentReceiver);

//---unregister the two BroadcastReceivers---
unregisterReceiver(smsSentReceiver);
unregisterReceiver(smsDeliveredReceiver);
}

@Override
protected void onDestroy() {
super.onDestroy();

//---unregister the receiver---
unregisterReceiver(intentReceiver);
}

public void onClick(View v) {
sendSMS("5556", "Hello my friends!");
}

public void onSMSIntentClick (View v) {
Intent i = new
Intent(android.content.Intent.ACTION_VIEW);
i.putExtra("address", "5556; 5558; 5560");

i.putExtra("sms_body", "Hello my friends!");
i.setType("vnd.android-dir/mms-sms");
startActivity(i);
}

//�-sends an SMS message to another device�-
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
}

این کلاس SMSActivity بود

 

اینم کلاس smsReceiver

 package net.learn2develop.SMS;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "SMS from ";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
if (i==0) {
//---get the sender address/phone number---
str += msgs[i].getOriginatingAddress();
str += ": ";
}
//---get the message body---
str += msgs[i].getMessageBody().toString();
}

//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
Log.d("SMSReceiver", str);

//---stop the SMS message from being broadcasted---
this.abortBroadcast();

//---launch the SMSActivity---
Intent mainActivityIntent = new Intent(context, SMSActivity.class);
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainActivityIntent);


//---send a broadcast intent to update the SMS received in the activity---
Intent broadcastIntent = new Intent();
broadcastIntent.setAction("SMS_RECEIVED_ACTION");
broadcastIntent.putExtra("sms", str);
context.sendBroadcast(broadcastIntent);
}
}
}

اینم manifest

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.SMS"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".SMSActivity"
android:launchMode="singleTask" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<receiver android:name=".SMSReceiver">
<intent-filter android:priority="100">
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>

</manifest>

من هنوز وقت نکردم ببینم چطور کار میکنه و چطور تو پروژه ام ازش استفاده کنم اگه متوجه شدید همینجا یه توضیح بدید

فقط میدونم درست کار میکنه

نظرات

afr_msb 9 سال پیش
ممنون حتما تست میکنم منم راه حلشو پیدا کردم یکم خلوت بشم با توضیح میذارم

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .