Hello! I'm writing a program for processing SMS from the bank and the idea to install a ringtone for SMS from the bank (I apologize for the tautology). but I don’t know how to “drown out” the default sound and play my sound. help who what can. thank!

    1 answer 1

    It is necessary to catch the new arrival of a new sms and in the notification of the processor set the desired ringtone notification. Schematically done like this:

    1) Install the Broadcast New Intercept Interceptor in the manifest:

    <receiver android:name=".SmsReceiver" android:permission="android.permission.BROADCAST_SMS" android:enabled="true" android:exported="true" > <intent-filter android:priority="999"> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> 

    2) We write the interceptor class SMSReceiver

     public class SMSReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //blah-blah } } 

    3) In the interceptor create a notification:

     nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notification = new Notification.Builder(context) .setSmallIcon(R.drawable.myIcon) .setContentTitle(notificationTitle) .setContentText(notificationText) .setWhen(System.currentTimeMillis()) .build(); notification.sound=ringToneUri; //ссылка на наш рингтон nm.notify(id, notification); //запускаем нотификацию 

    Some parts are deliberately not described :) This is so that life does not seem like sugar - sort it out.

    In general, the reception of SMS piece undocumented ...