save sms programaticaly same as default sms app
<p>I am trying to save sms to inbox programatically same as the default app does.Like i want to show notification,play tone which is set,vibrate as per settings.every thing should be same as if there is new sms has come.</p>

<p>To save sms in inbox i use following code  <a href="http://stackoverflow.com/a/872131/1140321">http://stackoverflow.com/a/872131/1140321</a></p>

<p>I am able to save sms to inbox as per above link.But unable to display default notificaiton and playing current set ringtone which is set by user</p>

<p>To display notification i have tried</p>

<pre><code>public synchronized void showNotification() {

    Notification notification = null;
    try {
        NotificationManager notificationMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationMgr.cancel(NOTIFY_ID);

        int icon = android.R.drawable.alert_dark_frame;
        CharSequence tickerText = "Message";
        CharSequence contentTitle = "Messages";

        CharSequence contentText = null;

        long when = System.currentTimeMillis(); // notification time

        Intent notificationIntent = null;
        PendingIntent contentIntent = null;
        notificationIntent = new Intent(this, MainActivity.class);
        contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification = new Notification(icon, tickerText, when);

        notification.setLatestEventInfo(this, contentTitle, contentText,
                contentIntent);
        notification.defaults = Notification.DEFAULT_ALL;
        notificationMgr.notify(IPA_NOTIFY_ID, notification);


    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>

<p>Above notification method takes care of ringtone and vibration.but apart from above code
i tried to play ringtone as below :</p>

<pre><code>void playTone() {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
            notification);
    r.play();
}
</code></pre>
