Question

I'm trying to send CallLog history via sms. Well the CallLog history is displaying in TextView but SMS is not working.

Code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call_log);
tv = (TextView) findViewById(R.id.call);

    getCallDetails();
}


private void getCallDetails() {
    // TODO Auto-generated method stub
    StringBuffer sb = new StringBuffer();
    Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
    int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER ); 
    int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
    int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
    int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
    sb.append( "Call Details :");
    while ( managedCursor.moveToNext() ) {
    String phNumber = managedCursor.getString( number );
    String callType = managedCursor.getString( type );
    String callDate = managedCursor.getString( date );
    Date callDayTime = new Date(Long.valueOf(callDate));
    String callDuration = managedCursor.getString( duration );
    String dir = null;
    int dircode = Integer.parseInt( callType );
    switch( dircode ) {
    case CallLog.Calls.OUTGOING_TYPE:
    dir = "OUTGOING";
    break;

    case CallLog.Calls.INCOMING_TYPE:
    dir = "INCOMING";
    break;

    case CallLog.Calls.MISSED_TYPE:
    dir = "MISSED";
    break;
    }
    sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
    sb.append("\n----------------------------------");
    }
    managedCursor.close();


    String str = sb.toString();
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage("5554", null, str, null, null);
    }
Était-ce utile?

La solution

Because it possible your message string length is more then one message length so use smsManager. divideMessage (String text) for sending message if string exceed SMS size limit as:

SmsManager sms = SmsManager.getDefault(); 

if(str.length()>160){
    ArrayList<String> smses = smsManager.divideMessage(str);  

        smsManager.sendMultipartTextMessage("5554", null,
                    smses, null, null);
 }
else{
      sms.sendTextMessage("5554", null, smses, null, null);
 }

and make sure you have added following permission in AndroidManifest.xml :

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

Autres conseils

Your Code is working well.

SmsManager sm=SmsManager.getDefault();

String phoneNumber="xxxxxxxxxx";
String message="test text message";

sm.sendTextMessage(phoneNumber, null, message, null, null);

I think you need to add this permission.

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

I tried it and it charged me too for 1 sent sms. :)

Hope it helps you.

THanks.

to send call log in message

SmsManager sms = SmsManager.getDefault();
ArrayList<String> part = sms.divideMessage(sb.toString());
sms.sendMultipartTextMessage("number to whom u wanna send", null, part, null, null);

now the receiver side will deal it as one message i try this block of its send in multi part but receive in one block of message

sender side

sender side

receiver side

receiver side

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top