I am using GCM to send push notifications to my Android application and when the user clicks the notification, they should be taken to a specified view in the application (For context: It's an event log).
I understand that in the simplest case, I just add some parameters to the intent that is starting the app.
However, my app requires some remote data to be available when entering my MainActivity. When starting the application normally, it's pointing to another activity, let's call it AppStartActivity. It's showing a Splash screen while downloading the neccessary data and launches MainActivity when it's ready.
When starting the app from a notification, the neccessary data may or may not be ready, depending on whether the app is currently in background (and if it has not been garbage collected). Therefore, I think I have to launch AppStartActivity when clicking the notification, and then somehow forward the Intent parameters and I'm not sure it's the right way. I have formulated some questions about this:
Is it correct to lauch AppStartActivity with the parameters I will need in MainActivity later and then just forward them when switching to MainActivity?
Is there a simpler way to do this, such as finding out the state of the application when clicking the notification and then choose either AppStartActivity or MainActivity depending on if the neccessary data is available? The reason I'm asking is that when I create the notification, the data may or may not be available, but it may change during the time passing before the user to interact with the notification. I understand that I can launch a new activity that is just checking the state and then launch either MainActivity or AppStartAcitivty, but it seems like it could be a bit too complicated...
I'm thankful for any input on this matter. Please let me know if I have left out some details.
as I understand it, I had a similar situation, and this was my solution:
when I receive the GCM, my onReceive method starts a service
for getting the remote datas. Only when these datas are
avaiable in a local content provider, I throw the notification to the user.
[edit]
You have to manage any network error with some notice, otherwise you may lose the GCM notification
Related
Note: I haven't coded anything but looking for a structure/keywords or ideas how it can be achieved.
Use Case:
I have an activity which basically shows some display/data/or does some operation etc when opened manually from button click, notification click etc. Now I want to display the same stuff when a particular condition is satisfied [like my geo location matches that I force to be my home or user home].
1. without user clicking any notification,
2. without opening the activity,
3. without clicking buttons, and
4. without opening the app.
So in short, I want my app to be launched when I am home or reach a geo fence, is it achievable?
I am aware of Pending Intents, but seems they need the activity to be opened once and register the intent, let me know if this is the only way to go.
Kindly help!
when a particular condition is satisfied
This is not possible in general. For example, Android has nothing built-in with the ability to do something automatically based upon when your neighbor's cousin's daughter posts something on Stack Overflow. Even though that is a particular condition that could be satisfied, Android does not know your neighbor, nor your neighbor's relatives, nor the neighbor's cousin's children, nor the online actions of your neighbor's cousin's daughter.
There are specific things that Android can handle that offer the ability to give you control for related conditions, such as AlarmManager for getting control at certain points in time, or JobScheduler for getting control periodically when the environment is proper (e.g., we have connectivity and are on a charger).
Your question uses a geofence as an example. The Play Services SDK offers geofence APIs that you can use, that can give you control when the user enters a particular region.
I want my app to be launched when I am home or reach a geo fence, is it achievable?
You are welcome to call those geofence APIs, providing a PendingIntent that points to a WakefulBroadcastReceiver, which in turn points to an IntentService, where you can go do something.
If by "my app is launched", you mean bring up one of your activities, while that is technically possible using an activity PendingIntent, you may make your users very unhappy for interrupting what they are doing (e.g., collecting Pokémon). Please consider using a Notification instead.
I am aware of Pending Intents, but seems they need the activity to be opened once and register the intent
Nothing of your app will ever run until the user manually runs your app (e.g., taps on your home screen launcher icon) or until something else uses an explicit Intent to start one of your components. At that point, you can call the geofence APIs, assuming that you somehow know where the user's home is.
Most likely, you need the user to spend time in the activity simply to collect the data from the user about where they want the geofences to be established.
I'd like to prevent my application from starting when an Android for Work profile is not available for my application (not yet configured, or deployed on the device). Instead, I'd like to be able to display a Toast like message telling the user to contact his IT administrator. Example of this at the bottom of this message.
Example:
Divide Productivity Suite of application displays this message (mail, notes, etc).
"Configuration from managing application required. Contact your IT admin for details".
Screen Capture
Is there a way to implement this? I've tried to hook into MainActivity onCreate function, or even put it directly in the Application onCreate() function. Hooking code in here seem to still have launched the application (the title bar is displayed despite there's no content displayed).
I was able to figure out how to determine if your Application was running on a for Work profile and display a alert dialog here:
Android for work - How to check if my application is running in the work profile?
Man i can give you specific topic . You can search for services instead of Activities. Activity codes performing only when application is running .
But you can call services everytime without your app is not running.
You can look here
Apparently, this was actually pretty trivial.
In your AndroidManifest.xml, you reference a new Activity that starts your main application. This activity will use the "Theme.Translucent.NoTitleBar"
When you are unable to configure Android for Work profile, use a Toast.makeToast() message to notify your user, then call finish() and return from your onCreate() function.
When you are able to complete Android for Work configuration, start your MainActivity by creating an Intent, set the action and category and then call startActivity() from your initial Activity.
I need to know when a certain intent (in my case ACTION_CALL and ACTION_CALL_PRIVILEGED which are called when the user or an app make a phone call) was sent without registering my activity to handle it.
I don't want to interfere with the normal handling of that intent, i.e. the activity that's supposed to handle it should still handle it the usual manner (in my case the OutgoingCallBroadcaster).
I read here a suggestion to drop the ACTION_CALL_PRIVILEGED intent and issue another one, but want to avoid it. Moreover, I don't want to use an activity for the ACTION_CALL and issue another since it will appear in the intent chooser as an option and I want it to be transparent to the user and to always work.
Also working with the ActivityManager object like this suggestion is not recommended for core logic as stated in the documentation of the getRecentTasks method.
Please tell me if this is possible in Android, and if so how.
Thanks,
Amitai
No. This isn't possible. If it were possible it would allow me to write an app that monitors a user's behaviour without him knowing it. ACTION_CALL is an Intent to launch an Activity. You can, of course, intercept this, but that is clearly not what you want to do.
There are broadcast Intents that are sent out during the "call" process. You can monitor these, but you'll have to register to listen for them. Since you indicated that you don't want to register any listeners you are pretty much out of luck.
Which is a good thing, because otherwise people would be able to write a "NastyWare" application.
I want to write an app to send an sms from a shortcut on a home screen. That is all.
I just can't understand within the framework how I can write such an app. Here's what I've tried so far and what my ideas are:
I wrote an activity that sends an sms using SmsManager within the onCreate() however, this just keeps on sending messages even though the code is not in a loop. I realise I must be not be using an activity the way it's designed to be used. The android application fundamentals article says an activity is for displaying a screen or gui, but I don't need a gui. I just don't know what component I need to to use.
A service? no, because I don't need something running forever in the background.
An activity? I guess no because I don't need a gui.
I had an idea to create a broadcast receiver which would respond to a broadcast, so my sens smsm code would be in there ready to send when it receives the signal. But how do i send the signal from an app shortcut on the home screen? What would be the entry point of the app.
I'm just really confused, I've read the tutorials and the app fundamentals and searched forums and not found the answer. There's is just a big gap in my knowledge of the android framework that needs filling I guess, once it clicks I'll be fine but I'm just stuck right now.
Thanks people.
Service does not have to run forever. You can control how long it works in the background, you can even create Service that will shoot once and disappear. Suggestion:
from your shortcut (app icon) start Activity. That will be activity with translucent background. To achieve that skip line setContentView() and define theme
#android:style/Theme.Translucent
in your AndroidManifest.xml. This way you will avoid black screen flash at Activity startup.
from that Activity start Service and call finish() on that Activity
perform SMS sending (you already know how) from Service. Maybe, you do not even need Service, you can send SMS from the translucent Activity.
call stopSelf() from your Service immediatelly or after some short timeout (wait for SMS sending result).
All described can be done smoothly through Widget framework. In that case you can even have custom button user may press on. So, that would be another approach.
I want my application to start when someone modifies a content provider. A setting to be specific. The settings framework calls "notify" when a value is set.
If my app was started I would use registerContentObserver() I guess, but is is not started.
Can define some intent-filter in my manifest that wakes up my application. A back up plan would be to have a service running all the time that has registered a listener, but that seems like a wast or resources.
Thanks, Ola
This isn't directly supported by the Android device because starting an app every time a ContentProvider's data changes is a path to really killing your battery. To do the query, you'd need to do it in a service, which as you said is understandably undesirable.
Secondly, starting an intent is a user action. Android really doesn't support allowing an application to start all on its own without user request... Doing so would be impolite! What if your user was doing something important and then your app pops up on top? Remember the user is in control, not you. Instead of starting an application, consider placing a Status Bar Notification so the user can deal with it when it's convenient for them.