ساعت سخنگو برای فارسی زبانان
| 9 | private static final String CHANNEL = "clock_announcement"; |
| 10 | @Override public void onCreate() { |
| 11 | super.onCreate(); createChannel(); |
| 12 | Notification.Builder b = Build.VERSION.SDK_INT >= 26 ? new Notification.Builder(this, CHANNEL) : new Notification.Builder(this); |
| 13 | android.widget.RemoteViews rv = new android.widget.RemoteViews(getPackageName(), R.layout.notification_large); |
| 14 | rv.setTextViewText(R.id.notificationTitle, "تايمگو"); |
| 15 | rv.setTextViewText(R.id.notificationText, "در حال اعلام ساعت…"); |
| 16 | b.setContentTitle("تايمگو").setContentText("در حال اعلام ساعت…").setCustomContentView(rv).setContent(rv).setSmallIcon(R.drawable.ic_status_clock).setOngoing(true).setOnlyAlertOnce(true); |
| 17 | startForeground(1201, b.build()); |
| 18 | } |
| 19 | @Override public int onStartCommand(Intent intent,int flags,int startId){ |
| 20 | speaker=new AudioTimeSpeaker(this); |
| 21 | // Enforce the preference at the service boundary as well as inside the |
| 22 | // speaker, so a stale caller can never produce the full time in Ding-only mode. |
| 23 | if (getSharedPreferences("settings", MODE_PRIVATE).getBoolean("dingOnlyMode", false)) { |
| 24 | speaker.playDingOnly(); |
| 25 | } else { |
| 26 | speaker.speakScheduledTime(); |
| 27 | } |
| 28 | new Thread(()->{try{Thread.sleep(15000);}catch(Exception ignored){} stopSelf();}).start(); |
| 29 | return START_NOT_STICKY; |
| 30 | } |
| 31 | private void createChannel(){if(Build.VERSION.SDK_INT>=26){NotificationChannel ch=new NotificationChannel(CHANNEL,"اعلام ساعت",NotificationManager.IMPORTANCE_LOW);((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).createNotificationChannel(ch);}} |
| 32 | @Override public void onDestroy(){if(speaker!=null)speaker.stop();super.onDestroy();} |
| 33 | @Override public IBinder onBind(Intent intent){return null;} |
| 34 | } |