-2

Hi I worked on application,in which the message are retrieve from web service. The websevice gives response like (contactnumber + "##" + message + "##" + Username). I want store message like inbox in the phone. Please any one give me some idea.

RAS
  • 8,100
  • 16
  • 64
  • 86
sad123
  • 1
  • 2

2 Answers2

0

Well you will have 3 steps : 1) contact webservice using an http request (you will find plenty tutorials on how to do this) 2) parse the response (in your case you split the string but it's not very robust ...) 3) store the message where you want (please be more precise on where you want to store it)

Estragon
  • 1,462
  • 11
  • 12
0

STEP 1: Get web message using HttpGet as:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("YOUR_WEB_SERVCE"));
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String webmesg = sb.toString();

STEP 2:

use TelephonyManager for getting your own mobile number as:

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String strmobinum= tm.getLine1Number();

AndroidManifest.xml:

<uses-permission android:name= "android.permission.READ_PHONE_STATE"/>

STEP 3:

USE SmsManager for sending sms :

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(strmobinum, null, webmesg, null, null);

AndroidManifest.xml:

<uses-permission android:name="android.permission.SEND_SMS"/>
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213