GCM Message opening Tab of Tabhost - android

I have a fairly basic android app that is a tabhost of 4 tabs, each one opens a webview. The app also has GCM all setup and currently can receive messages fine. When a message is received though, you click on it and it simply opens the app the same way clicking on the App icon would open the app. What I am trying to do though is open a particular tab inside the app when someone clicks on message and what would be even better is if I could open any tab depending on what the message is. Is this possible? If so, how would I go about doing this?
From what I have found so far, I think this involves something with adding an additional item in the payload of the message such as
{
"registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"data" : {
"message" : "Text notification goes here",
"tab" : "2"
},
}
and then possibly doing something with the intents which I am not sure how to do. Am I on the right track and can anyone help me with this?

You can add an extra to the pending intent that you pass to the notification that will indicate which tab to open.
And when the activity starts check for that extra and open the tab accordingly.

Related

how to show custom dialog box when android application receives notification

popup message feature like whats app, caller id like the true caller, I am trying to make the same thing.
I tried using a broadcast receiver but I do not know how to show the dialog box when a broadcast receives a notification.
a pop-up message like WhatsApp shows when a notification arrives on a phone.
Set mainactivity as a launcher screen. In the mainactivity before setContentView method calling check if the intent has extra parameters as per your requirement. If yes, then finish the current activity and start DialogActivity.

Building a task stack for activity started after Firebase Notification

Using Firebase Cloud Messaging, when the app is in the background and a message has arrived, the message goes to the system tray. When the user than clicks on the notification, the app gets launched and the launcher activity gets the message data in the Intent.
In my case, this notification is about some new results, so when pressed, I want to start a ResultsActivity.
In order to make this happen I do this in the OnStart of the LauncherActivity
:
Intent intent = getIntent();
String searchId = intent.getStringExtra("search_id");
if(searchId != null){
Intent resultsIntent = new Intent(LauncherActivity.this, ResultsActivity.class);
resultsIntent.putExtra(ResultsActivity.SEARCH_ID_EXTRA, searchId);
startActivity(resultsIntent);
}
This all works great.
The problem is now when clicking on the "up" arrow on the app bar, the app does not go to the parent activity that is defined in the manifest (which is not the launcher activity) but to the launcher activity. This is not surprising since the ResultActivity is started from the LauncherActivity, but this is not the wanted behavior. The wanted behavior is for the back arrow to send to the parent activity, which happens to be MainActivity.
I know there is the TaskStackBuilder for that kind of stuff, but I don't know how I can apply that pattern to my case here where I start the activity "normally" from another activity and not from some Notification Builder.
Is TaskStackBuilder the right solution here? If so, how can I change the code above to use it? if not, what is the right solution for this?
What I ended up doing is on the server side, with the firebase cloud messaging admin, instead of including a firebase_admin.messaging.Notification object in the firebase_admin.messaging.Message object I am then sending, I just put the notification title and text in the Message's data, and then build a notification by myself normally in MyFirebaseMessagingService. Since I'm now building the notification by myself I can add the TaskStackBuilder normally.
I guess this doesn't really answer the question of how to add a back stack when not using Notification.Builder, but it's probably a better solution anyway.

Show *only* a toast (no UI) after sharing text into an app?

I'm a starting Android developer and would like to know how to achieve this:
1# User is using e.g. Chrome
2# User wants to share the page (meaning: the URL, which is text) into an app
3# User chooses the app from the share menu
4# The app shows only a small notification on top of Chrome (current foreground app, which is the sender of the intent)
So the app would receive the intent from Chrome and do something with it, but wouldn't change the foreground app. It would stay in the background and show only a very small notification to the user that the sharing of the URL into this app actually succeeded. Toast or something like that.
This is basically the way for instance Pocket handles sharing into it.
How can I achieve this? IntentService? I cannot seem to find the correct answer to this. Theme.NoDisplay, Intent, IntentService – I cannot figure out the correct way since I'm not too familiar with Android yet.
Thank you a lot in advance!
Use the NoDisplay theme (update activity declaration in manifest) in the activity that does your sharing work as follows:
android:theme="#android:style/Theme.NoDisplay"
This will prevent the activity from being displayed.
Then once the activity starts, do your sharing task, display the Toast and call finish()
finish your activity onResume(). It will not shows any of Your Activity.
You can do like this:
protected void onResume() {
super.onResume();
finish();
}

how to open particular fragment when notification is clicked

I have a notification in notification bar and i have 3 fragments in one of my activity. i want when i click the notification it will open particular fragment, Like what facebook notification do. I tried to search it on google n everywhere else but didnot match what i need.
Example: i have 3 fragments
1 - for redeem value.
2 - for recharge.
3 - for anything.
Now if i get notification from Admin Panel like you can redeem your value, then that notification will open that particular fragment. If i get notification to recharge then it will open that particular fragment like this i want all working.
Hope you clear, if not then please let me know.
you can use this link for open notification in fragment you should use Pending Intent for it and set your fragment with name and open it with pending intent, link1
link2

how to to pop up and ask for user input on android after receiving broadcast

hey, im new to android development and trying to make my first application.
What im trying to implement is a feature i've seen in Handcent SMS: the popup notification.
So far, my application has a broadcast receiver that uses Toast to display an incoming SMS message.
However, instead of a Toast notification, I want to make a pop up window that shows the message and offers users a space to type a reply and a button to send. (also a button to simply acknowledge the message without replying)
how would I accomplish this?
can I make my own 'floating' activity and use startActivityForResult?
would that have to be fired from inside of a service since broadcast receivers arent supposed to do any heavy lifting?
or can i use NotificationManager or something.
You need to have an activity (layout+events etc) and in order to be 'floating' you need to set it's theme to dialog, this can be done in the manifest file where you define your activity
Something like
<activity android:name=".utils.TextEntryActivity"
android:label="Type in the value" android:theme="#android:style/Theme.Dialog" />
For starting other activity from BroadcastReceiver you can use the passed Context of the onReceive event.
context.startActivityForResult(...)

Categories

Resources