آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
مشکل عدم دسترسی خریداران پیشین به برخی آموزش ها برطرف شد
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

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

SMS
afr_msb  7 سال پیش  7 سال پیش
0 0

سلام من در ارسال 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);
}
0 0
یعنی برای خط خاموش هم میگه تحویل داده شد؟ (7 سال پیش)
0 0
بله و فیلد مربوطه را در سرور true ارسال میشه (7 سال پیش)
0 0
خب نرم افزار پیام رسان پیش فرض خود گوشی هم همینجوریه. (7 سال پیش)
0 0
وقتی با گوشی پیام ارسال میکنیم روی پیام بزنین قسمت جزئیات مشخص کرده پیام ارسال شده یا نه . سوالم اینه چطور میتونم از امکان گوشی استفاده کنم ؟ (7 سال پیش)
0 0
برای این باید جزییات پیام را در بیارید که جدول کاملش توی نت هست و ساختار دیتابیسش اگر به نتیجه نرسیدید اعلام کنید (7 سال پیش)
0 0
نه متاسفانه به نتیجه نرسیدم (7 سال پیش)
0 0
لینک (7 سال پیش)
0 0
لینک (7 سال پیش)
0 0
ای کاش یه نفر بهم میگفت چه کنم . اصلا وارد swich case تابم نمیشه . خیلی حیاتیه کمک کنین (7 سال پیش)
0 0
شما جزییات پایم های ارسالی را می خواهی یا فقط گزارش تحویل؟ (7 سال پیش)
0 0
سلام منم توی پروژه ام همچین مشکلی دارم فعلا بیخیالش شدم چون تنها حدسم اینه که شاید توی امولیتور مشکل داره . در این مورد لطفا با بنده در ارتباط باشید. (7 سال پیش)
0 0
نه من روی گوشی و سرور تست میکنم اصلا جواب نمیده (7 سال پیش)
0 0
شما هم اگر راه حلشو پیدا کردین خبر کنین (7 سال پیش)
0 0
بله چشم. نگران نباشید حتما پیدا میکنیم (7 سال پیش)
0 0
سلام یه پروژه پیدا کردم که کاملا درست کار میکنه و گزارش ارسال اس ام اس و تحویل اس ام اسش درسته (7 سال پیش)
+1 0
ممنون حتما تست میکنم منم راه حلشو پیدا کردم یکم خلوت بشم با توضیح میذارم (7 سال پیش)
 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
فرهاد  7 سال پیش
0 0

 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>

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

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

+1 0
ممنون حتما تست میکنم منم راه حلشو پیدا کردم یکم خلوت بشم با توضیح میذارم (7 سال پیش)

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