Why Unable to read Message From "Android Device" Using GSMComm Library ,C# - c#

I am Using GSMComm Library to send and receive Messages (Desktop App)...
Sending Code Works Perfectally..
The Problem is when a message Received , I Was Unable to Read the Message while using Android Device,Replaced At-least 4 Samsung Devices , However It was working Perfectly with GSM-3G Devices
Error Shows Up at Following Line
DecodedShortMessage message = messages[indexx]; with Error Message "Index was outside the bounds of the array."/
Is Android doesn't permit to read Message from Phone Memory while permitting to send message?
I Tried everything that i can,But can't help myself..
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e)
{
try
{
IMessageIndicationObject obj = e.IndicationObject;
if (obj is MemoryLocation)
{
MemoryLocation loc = (MemoryLocation)obj;
string storage=loc.Storage;
int indexx = loc.Index;
DecodedShortMessage[] messages = comm.ReadMessages(PhoneMessageStatus.All, loc.Storage);
//Error Shows up in next Line ,
//Exception Message is "Index was outside the bounds of the array."
DecodedShortMessage message = messages[indexx];
SmsPdu pdu = message.Data;
if (pdu is SmsDeliverPdu)
{
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
MessageBox.Show(data.OriginatingAddress.ToString() + data.UserDataText.ToString());
}
return;
}
MessageBox.Show("Error: Unknown notification object!");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message + " (" + ex.GetType().ToString() + ")");
}
}
References Already Tried
Official Site
Code Project Bluck SMS Sender
Send Receive SMS

yes as i read from forums android doesn't permit to read Message from Phone Memory with gsmcomm you can use a android client to send sms from android to pc by socket or if you have a lot of money you can use androino i see an article about how receive and send sms.
i have a question about how to get the sender and the receiver number from the SmsDeliverPdu obeject because i need the sender and the receiver to validate the sms or how to get the sim number of the phone

Related

How to fix exception Device xxx disconnected while writing characteristic with yyy in xamarin forms?

I am creating a BLE app where I am successfully connecting to a BLE device. I am able to read the GATT characteristics as well. But when I try to do write operation I get exception
Device xxx disconnected while writing characteristic with yyy
This is my code
private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
{
try
{
await adapter.ConnectToDeviceAsync(device);
var sb = new StringBuilder("Getting information from Device Information service: \n");
var characteristics = await deviceInfoService.GetCharacteristicsAsync();
var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002b0f-0000-1000-8000-00805f9b34fb"));
//{
try
{
deviceInfoService.GetCharacteristicAsync(GattCharacteristicIdentifiers.DataExchange);
if (characteristic != null)
{
var sbnew = new StringBuilder("BLE Characteristics\n");
byte[] senddata = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(SendMessageLabel.Text) ? "0x21" : SendMessageLabel.Text);
await Task.Delay(300);
var newbytes = await characteristic.WriteAsync(senddata);
byte[] characteristicsvalue = characteristic.Value;
var str = Encoding.UTF8.GetString(characteristicsvalue);
sbnew.AppendLine($"Characteristics found on this device: {string.Join(", ", str.ToString())}");
CharactericsLabel.Text = sbnew.ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return CharactericsLabel.Text;
}
catch (Exception ex)
{
return ex.ToString();
}
}
After some search I found that I need to pass hexadecimal value.Even I tried sending hexadecimal value as you can see in code but it's not working. For android its working fine but for iOS it is still showing this exception.I'm using device Iphone 8 plus and OS version of Iphone is 13.5.1.The write operation works in Light Blue app which I downloaded from App store for iOS. My write type is set to default which is write with response. But it is giving exception in my xamarin app only for the iOS part. I'm using latest stable version 2.1.1 of Plugin.BLE. I have no clue how to fix this any suggestions?
I fixed this exception by getting write without response for characteristic from the peripheral side.

How to set status after email reading from Google Api

Usually in normal mail the unread status will be changed as read
after we visit that mail like the same way how to find the status
as read while reading email content in google api code in c#
Messages.modify method allows you to make changes to the message. You need to modify the message and remove the UNREAD label. The message will then appear to be read
public static Message ModifyMessage(GmailService service, String userId,
String messageId, List<String> labelsToAdd, List<String> labelsToRemove)
{
ModifyMessageRequest mods = new ModifyMessageRequest();
mods.RemoveLabelIds = "UNREAD";
try
{
return service.Users.Messages.Modify(mods, userId, messageId).Execute();
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
return null;
}
Not on access
This method requires one of the following scopes of access
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify

How to take mvc c# server errors +number to line number

Hi I've coded my MVC c# application and it's all fine, however there does seem to be a few bugs. This being one of my first applications, I'm not surprised.
The application though is internal and so I do get good feedback from the users.
They do give me the screens shots 'Server Error in ........ Application'
This gives me the controller action which does help narrow down the error.
However how do I turn the +number at end of the line to an actual line number.
I'm aware that this is some sort of byte offset, but getting a rough idea of the line number would be helpful. Is there a plugin or something I can use?
Or is there another way to handle these. I've got a Base controller that all the controllers extend from - I've seen some things that say you can use this to write to a file to give you information about the error. If I made it a generic file (similar to the php error file) then that would help me with any application I make.
You can handle server errors in Global.asax inside Application_Error() method. Create a well designed error page and save it somewhere inside your project. In global asax create a method and put error handling code inside it. See below for example code.
protected void Application_Error()
{
if (httpContext.AllErrors != null)
{
// you can handle message
var message = HttpUtility.HtmlEncode(httpContext.AllErrors[0]);
//you can redirect ugly server error page to the one you created
httpContext.Response.Redirect($"~/Error/Global");
}
}
Just developing on what hhh's answer here.
This is what I've got at the end.
protected void Application_Error()
{
if (this.Context.AllErrors != null)
{
var p = Path.Combine(Server.MapPath("~"), "Errors.log");
var message = DateTime.Now.ToString();
message = message + " " + this.Context.User.Identity.Name;
message = message + " " + this.Context.Request.Url;
message = message + Environment.NewLine;
message = message + "Post";
message = message + Environment.NewLine;
string[] keys = this.Context.Request.Form.AllKeys;
for (int i = 0; i < keys.Length; i++)
{
message = message+keys[i] + ":" + this.Context.Request.Form[keys[i]];
message = message + Environment.NewLine;
}
message = message + Environment.NewLine;
// you can handle message
message = message+ HttpUtility.HtmlEncode(this.Context.AllErrors[0]);
message = message + Environment.NewLine;
message = message + "----------------------------------";
message = message + Environment.NewLine;
System.IO.File.AppendAllText(p, message);
//you can redirect ugly server error page to the one you created
}
}
Basically giving you a file with all the key variables in the there.
Feel free to modify as you wish.

Sending multi part sms with GSM using AT Commands

I have a windows application for sending SMS connecting to a GSM Modem. I only use AT Commands for connecting to port and sending text.
My problem is I can't send a message more that one part (each part is 160 characters for English and 70 characters for Farsi).
Here is the part I command the port to send sms using AT commands:
ExecCommand(port, "AT", 300, "No phone connected at " + strPortName + ".");
ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
var command = "AT+CSCS=\"" + "HEX" + "\"";
ExecCommand(port, command, 300, "Failed to support unicode");
ExecCommand(port, "AT+CSMP=1,167,0,8", 300, "Failed to set message properties.");
command = "AT+CMGS=\"" + phoneNo + "\"";
ExecCommand(port, command, 300, "Failed to accept phoneNo");
message = message.ToCharArray().Select(Convert.ToInt32).Select(value => String.Format("{0:X}", value)).Aggregate("", (current, hexOutput) => current + hexOutput.PadLeft(4, '0'));
command = message + char.ConvertFromUtf32(26) + "\r";
var recievedData = ExecCommand(port, command, 3000, "Failed to send message");
And here is ExecCommand method
public string ExecCommand(SerialPort port, string command, int responseTimeout, string errorMessage)
{
try
{
// receiveNow = new AutoResetEvent();
port.DiscardOutBuffer();
port.DiscardInBuffer();
receiveNow.Reset();
port.Write(command + "\r");
//Thread.Sleep(3000); //3 seconds
string input = ReadResponse(port, responseTimeout);
if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
throw new ApplicationException("No success message was received.");
return input;
}
catch (Exception ex)
{
throw new ApplicationException(errorMessage, ex);
}
}
General AT command handling
You are on the right track, I am pleased to see several basic things done right (terminating AT command lines with \r, waiting for "\r\n> " for AT+CMGS, and waiting for the OK final result code instead of sleeping), very good start!
You do need however to change the structure somewhat. First you need to handle all the other final result codes and not just OK. And you should treat the AT+CMGS command differently from the other commands since you should wait for two things (first the prefix and later the final result code after sending the message text) for that command compared to waiting only for one thing (e.g. the final result code) for those. Also all responses from the modem are complete lines (except the "\r\n> " prefix), so change your algorithm to process the response(s) line by line.
String input;
do {
input = ReadLine(port, responseTimeout);
} while (!isFinalResultCode(input));
None of the commands you are using in the question produces an intermediate response for consumption, but if you were to run a command like AT+CPBR you would consume those intermediate responses inside that loop (and you would have to move the final result test into the loop before attempting to consume the line as an intermediate response).
You can see the is_final_result function in atinout or corresponding functions in ST-Ericsson's U300 RIL (see link and notes in this answer).
Multipart SMS
I think this is not possible in text mode. See the link suggested by Naser Asadi for details on multipart SMS in PDU mode. Also some useful information at
http://mobiletidings.com/2009/02/18/combining-sms-messages/ and http://developer.nokia.com/community/discussion/showthread.php/109602-Concatenated-SMS-in-PDU-Mode.

push notification iphone error (moon aspn)

I'm using the moon aspn library for sending push notifications in asp.net and c#. I'm encountering the following error: Call to SSPI Failed; in the inner exception i have: Unknown error while processing the certificate; error code: -2147467259.
here is my code:
private void SendQueueToapple(IEnumerable<NotificationPayload> queue)
{
int i = 1000;
foreach (var item in queue)
{
if (!_conected)
{
Connect(_host, NotificationPort, _certificates);
var response = new byte[6];
--> --> --> _apnsStream.BeginRead(response, 0, 6, ReadResponse, new MyAsyncInfo(response, _apnsStream));<-- <-- <--
} try {
if (item.DeviceToken.Length == 64) //check lenght of device token, if its shorter or longer stop generating Payload.
{
item.PayloadId = i;
byte[] payload = GeneratePayload(item);
_apnsStream.Write(payload);
Logger.Info("Notification successfully sent to APNS server for Device Toekn : " + item.DeviceToken);
Thread.Sleep(1000); //Wait to get the response from apple.
}
else
Logger.Error("Invalid device token length, possible simulator entry: " + item.DeviceToken);
}
catch (Exception ex)
{
Logger.Error("An error occurred on sending payload for device token {0} - {1}", item.DeviceToken, ex.Message);
_conected = false;
}
i++;
}
}
This might be a certificate related problem. You have to create .cer and .p12 files. Pay close attention to these files. You first generate the .cer and I'm not going into detail here. There's enough material available. The problem comes when generating the .p12 file.
In your mac, go to the Keychain Access. Select "My Certificates" from the left pane. There you will see a list of certificates. Select the certificate you generated for push notifications. Right click and export. Make sure you DO NOT expand the certificate perform this step on the private key. That's where thing starts to go wrong.

Categories

Resources