how to play Push notification text using speech? - java

I want to play coming push notification text in android using Text to speech control. whenever push notification generate in my device that time application is close so I want to play push notification text using text to speech without opening application.
Please Help me.

Use a service for any background tasks(slideshare.net)
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use. Each service class must have a corresponding
declaration in its package's AndroidManifest.xml. Services can be
started with Context.startService() and Context.bindService().
So basically, its just something that runs in the background, including when the screen is off. Now, all you have to do, is put your TTS (text to speech) code in a service. That's easy, just implement the Text to Speech API and speak:
TextToSpeech t1;
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
obviously, there are callback methods that have not been implemented in the preceding example, but here are the references (https://developer.android.com/reference/android/speech/tts/TextToSpeech.html)
If you are starting the notification from a broadcast receiver, you can simply call startService() from the receiver, or add the TTS code in the broadcast receiver (although that would be bad practice since broadcast receivers are solely meant to receive)
If you need any more help, feel free to ask.

Related

Suggestions for transferring int value from Service to MainActivity?

I have a Service that is started from a pendingIntent.
This service gives either a 1 or 2 int (there's a notification that contains a button, that once pressed returns 1 then 2 over and over.) Need to transfer this int to my mainActivity to then say (in my mainActivity)- if (ServiceClass.getNum ==1) then mToggle.setChecked(true) else (false).
I heard a bunch of different suggestions on how to do this. Some of those suggestions include Binding to the activity, using a Local Broadcast receiver? Also my mToggle button needs to still be able to change states even if the Activity is in the background or closed.
Any suggestions on the best course of action is appreciated.
For communicating between Android activity and service we can use broadcast receiver.
you can see this https://developer.android.com/guide/components/broadcasts

Android how to pass pointer on List and receive it back

I'm developing a simple Application. It has 3 buttons (start record, stop record, send info to the server). I want to record my voyage on the map, and I implemented it, but it works only when Activity is onResume(), so now I implementing sticky service, which will do exactly the same, but in the background. So service will fill ArrayList<MapPoint>, and then I have to receive it back somehow to my activity. It is not necessary to pass ArrayList to Service, but I have to receive it back to send it to the server in onDestroy() method. Please, help.
I thinks you can put the value in shared preferences and then pull it back in the activity

Write power off and power on button press to file

I have been poking around to figure out how to do this with Service or Activity, or Broadcast Receiver and I can't seem to get a definitive answer.
I want to be able to write the following data event(s) with timestamp to a file with an application that is running in the background.
Power button pressed on
Call being sent outgoing
SMS message being sent outgoing
It is an application that I am attempting to build for logging phone usage with the timestamp written to a file.
Went through many explanations and this is the only one that seemed to make sense:
https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
Any information or tutorials on this would be greatly appreciated.
I would do the following:
Create a broadcast receiver that based on the intent received determines the type of event. Have a look to the Command design pattern.
The command launches a new intent using the Broadcast receiver as a Context.
Create a service that is able to handle this intent, so it starts, sends some data or stores it wherever, and shutsdown. Have a look to the IntentService class.
Create an activity to show the content you have stored or to explain the user what your app does.

Chatting Activity via SMS Android Application

I'm trying to develop an application that allows users to chat with each other via sms..
I created an activity that sends and receives sms, but I don't know how can I make their chatting moving up (as in SMS messages in iPhone it seems like chatting page),
All I did is make the msg in edit text and receives it in textview ...
actually i don't know what's the name of this thing to make search ...
can anyone inform me what's the name of this technique!!!
I'm really confused ='.
What I would probably do in your case is implement the chat history as a ListView, sorted by entry timestamp. When you send or receive new messages, just add them via your ContentProvider and tell the ListView to scroll to the bottom position. It's a more code, but examples exist, and it's more flexible than hacking up a TextView.

How to implement an Android detail notification?

This has probably been asked before, but I can't find a good way of implementing it. I'm trying to write a program that manages a form of messages, and these messages are received from an external data source. This all works. However, the problem comes when I try to notify the user: I would like to have the notification jump directly to the message when it is touched, but this seems to mess up the back stack. This is probably best explained by example:
I open up the message list, the main activity, and browse for a while.
I hit home and go into another app (let's say Music).
A new message is received. A notification comes up, which I touch. The message detail view is displayed.
Now I hit Back. What I want to have happen is that I return to Music, but unfortunately, Back sends me to the message list, and then hitting Back will return me to music.
The both the list and the detail activities are marked as "singleTop", and the exact flags that I use for the notification Intent are:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
I figure if the Messaging application can do this, why can't I?
I have found one way to do this, but it's still not ideal:
Change the detail activity to have a different task affinity from everything else.
Add android:launchMode="singleTop" and android:excludeFromRecents="true" to the detail activity's manifest entry.
(Optional) Modify the list activity to open the detail activity with FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET. (This makes the task more like the built-in messaging app.)
The only fault to this scheme is that switching back over to the app will always go back to the list activity, but at least it is consistent. If someone else has a better way to do this, I'd love to hear it.

Categories

Resources