Make action in another app trigger an action in my own - java

I've looked into using Google's Calendar API and provider and have found it is possible to read the user's calendar. This can be used to keep my app's inner calendar in sync with the Google calendar IF the user opens the app after making a change to their Google Calendar.
I am wondering if it is possible for my app to be notified whenever a change occurs in the Google Calendar so that my app may copy those changes and keep it in sync within my app's own online database.
This is because my app's functionality requires users to compare calendars but it is useless if a change occurs in the Google Calendar and then cannot be seen until the user opens my app again.
All ideas are appreciated and thanks in advance.

Yes, it is possible to be notified whenever a change occur in your Calendar. Notifications allow you to find out about changes to events in your calendar.
The Google Calendar API provides push notifications that let you watch for changes to resources. You can use this feature to improve the performance of your application. It allows you to eliminate the extra network and compute costs involved with polling resources to determine if they have changed. Whenever a watched resource changes, the Google Calendar API notifies your application.
To request push notifications, you need to set up a notification channel for each resource you want to watch. After your notification channels are set up, the Google Calendar API will inform your application when any watched resource changes.
POST https://www.googleapis.com/calendar/v3/calendars/my_calendar#gmail.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://exampledomain.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}

Related

Which Android Classes can be used to enable an action for every event in a specific calendar?

I'm looking to see if this problem is feasible. I want to create an Android app that allows a user to enable Do Not Disturb for every event in user-specified calendars. I've already looked into the AlarmManager class, and it does not seem to work for this purpose. A single AlarmManager instance would work for one half of one event (turning Do Not Disturb On). Another AlarmManager instance would be required to turn Do Not Disturb off. This would have to repeat for every event (which is variable) in the specified calendars. Is there an easier approach to this, or am I looking at this problem all wrong? I know that this has been done in stock Android, but it only works for one calendar at a time. If there is a better solution to this, could you point me toward the proper Android SDK classes? I do not need a code example. Thanks.

How do you request and release audio focus in Here Maps SDK Android

I see in the Here Maps Documentation they provide a very small example of how to request audio focus for voice navigation.
https://developer.here.com/documentation/android-premium/dev_guide/topics/audio-management.html.
However how should this work? Should we just always request and hold onto "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK". Is there a way to get callbacks into when Audio is about to start and then request and release?
Also how would we handle if we get a phone call, and we want to pause the navigation voice?
NavigationManager has a AudioFeedbackListener, you should be able to get callbacks by implementing the listener : onAudioStart() , onAudioEnd().
-

queryPurchases() vs queryPurchaseHistoryAsync() in order to 'restore' functionality?

I'm using the Play Billing Library in order to trigger and manage purchases which in turn unlocked extra functionality within an app. This part is working.
However, what is the best way to 'restore' purchases. Say for example someone who has bought the app buys a new phone. Logs in to the Play Store, downloads my app and then finds that the payment screen to 'upgrade' is being displayed. iOS has a specific method for this but I'm not aware of one for Android.
My thoughts are to query the Play Store and confirm whether the account has previously SUCCESSFULLY purchased the item, if so then I will call the local upgrade function within the app.
It appears there are two similar methods. But which one should I used in this scenario? Where a user has either wiped their phone or bought a new one?
queryPurchases()? Or queryPurchaseHistoryAsync()?
You should use queryPurchases. That gives you all the current active (non-consumed, non-cancelled, non-expired) purchases for each SKU.
queryPurchaseHistoryAsync won't do what you need because it will only give you a list of the most recent purchases for each SKU. They may have expired, been cancelled or been consumed, and there's no way to tell. Therefore this response can't be used to tell what purchases to apply in your app.
So far as I can see, the only valid use for queryPurchaseHistoryAsync is to provide a user with a list of their purchase history. It's a bit of an oddball.
Note also: queryPurchases is synchronous so in most cases it needs to be run in some kind of background worker thread. I run mine in an AsyncTask.
Per documentation queryPurchases uses the Play Store app cache to get the results while queryPurchaseHistoryAsyncactually checks the Purchase AP for the most recent purchases. So, in your case you should check the Asyncmethod.
queryPurchases
Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.
queryPurchaseHistoryAsync
Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
Also, make sure to check the documentation. It recommends to Cache purchase details on your servers.
https://developer.android.com/google/play/developer-api.html#practices
I know it's a bit late, but I just discovered this myself. Sharing my answer for others to benefit.
So I learned that queryPurchases() is cached locally on your device, but is updated when you call queryPurchaseHistoryAsync()
I discovered from this Stackoverflow answer here
So my solution, is when wanting to restore a purchase on a new device, or a fresh install of my app. Call queryPurchaseHistoryAsync() Then in the callback onPurchaseHistoryResponse() call queryPurchases() and look within the List<Purchase> from the PurchasesResult for the purchase status of any of the user's past purchases.
If there's an expected purchase your app can grant the entitlements of their past purchase.
The documentation has been updated for the latest versions of BillingClient. queryPurchases() is deprecated. Also note that queryPurchases() only ever returned purchases made by the current device, so that method will not inform your scenario of a new wiped phone. To get accurate information use the async calls.
queryPurchasesAsync() will return all active subscription and unconsumed one-time Purchase objects for the sku type provided. It gets the purchases from the local Play Services cache, so there are no guarantees the cache will contain purchases from another device in your "new phone" scenario, and no guarantees the cache will yet be current in your "wiped phone" scenario.
queryPurchaseHistoryAsync() will make a network request and return the most recent PurchaseHistory object for each sku matching the provided sku type, even if cancelled or consumed.
Also, to perform the upgrade call launchBillingFlow() with the appropriate BillingFlowParams and BillingFlowParams.SubscriptionUpdateParams for the sku you now know to be purchased.

Getting exceptions from reccurent events in Google Calenader API v3

I have been developing an application to download whole calendars from all users in domain and save them in ICS format. The app is written in Java. I get access using 2L OAuth. So far I'm able to get most of calendar's data, excluding exceptions from recurrent events. Google API docs say that every recurrent event should contain a list of recurrence, including EXRULEs. But when I call the API I got only recurrent rule without exception.
It there any way to get these exceptions?
You get the exceptions as regular item and
event.getOriginalEvent()
will return reference to reccuring event.

Trap incoming call and hit a web service and display a response on "call receive reject panel" of Android?

I want to create an android app which will do the following
Traps/listens to an incoming call event ( im aware this step may have duplicates on SO but for the sake of completeness, im asking)
Takes over the control and hits a web service ( HTTP POST ) to get some info from the internet
And display the same as an "alert widget" on top of a "call receive/reject buttons", usually a place where we get "face" of the contact.
basic question is , is it feasible to develop such an app on stock android ? if yes , how ?
What are the consequences , if any ?
The solution should work on latest Android releases as well ( 2.3 onwards, 2.3 had a controversial patch which broke may apps relying on private telephony api of android )
http://developer.android.com/reference/android/content/BroadcastReceiver.html states that,
In particular, you may not show a dialog or bind to a service from
within a BroadcastReceiver. For the former, you should instead use the
NotificationManager API. For the latter, you can use
Context.startService() to send a command to the service.
For the 1) part you can create a BroadcastReceiver and listen for the
TelephonyManager#ACTION_PHONE_STATE_CHANGED action.
This will handle your call event.
For the 2) part to need to write an AsyncTask that performs the HttpPost action to your webservice. There are many tutorials available on the web on how to go about doing the HttpPost action.
Now, whenever you implement an AsyncTask, you have a onPostExecute method. Inside that method you can do your 3rd part of displaying using the Alert Dialog.
Hope it helps,
All the best
Cheers

Categories