Android TV: How to prompt user to add Google account - android-tv

Users of my Android TV (Nexus Player, NVIDIA Shield TV, Razer Forge TV, etc.) app sometimes do not have a Google account linked to their device. I want my app to send them to the Android TV "Add Account" activity.
Here is the code that I have tried:
Intent intent = new Intent();
intent.setAction(Settings.ACTION_ADD_ACCOUNT);
intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[]{"com.google"});
startActivity(intent);
This code does not work, although in the logcat I see the following:
I/ActivityManager: START u0 {act=android.settings.ADD_ACCOUNT_SETTINGS cmp=com.android.tv.settings/.accounts.AccountSettingsActivity (has extras)} from uid 10089 on display 0
Why does this do nothing?

This works:
Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, false, null, null, null, null);
startActivityForResult(intent, 1);

Related

Google Drive API - more than one hit for a single notification

I have created a channel which is created successfully
public static Channel CreateChannel(DriveService service,string ChannelGuid)
{
var pageToken = service.Changes.GetStartPageToken().Execute();
Channel ch = new Channel();
ch.Id = ChannelGuid;
ch.Type = "web_hook";
ch.Address = "https://abcd.efgh.com/home/SyncGoogleDoc"; //dummy url
var result = service.Changes.Watch(ch, pageToken.StartPageTokenValue).Execute();
return result;
}
and when any file added, update, delete from the googlr drive api i got notification as well
Once I receive a change notification I echo '200' string, as it is recommended in Google Drive API reference:
but problem i am getting notifications twice for each add/update call
and i need to run a sync job which start syncing my files twice
What possibily i am doing wrong ?

Disable sound for local notification

I'm trying to display a local notification without a sound using react-native-firebase, is that possible?
I have tried playing around with the AndroidNotification class, but couldn't find a way to do this.
const notification = new firebase.notifications.Notification()
.setNotificationId("notificationId")
.setTitle("Title")
.setBody("Text")
.android.setBigText("Big Text")
.android.setColor("#f04e29")
.android.setAutoCancel(true)
.android.setOnlyAlertOnce(true)
.android.setChannelId("channel")
.android.setLargeIcon("ic_launcher")
.android.setSmallIcon("ic_notification");
firebase.notifications().displayNotification(notification);
I would like for the notification to be displayed without any noise at all.
From my own experience, two things have to be taken into account:
No setSound method must be called or no sound properties should be set
When developing for Android API level >=26, the Android Importance passed as third argument of the Channel method has to be set to Low, Min or None. Otherwise the default sound is played anyway. So an example of creating your Channel (e.g. in the componentDidMount of your App.tsx):
const channel = new firebase.notifications.Android.Channel(
"testNotification",
"Test Notification",
firebase.notifications.Android.Importance.Low
)
firebase.notifications().android.createChannel(channel);
And then showing a nonobtrusive notification:
const notification = new firebase.notifications.Notification()
.setTitle("My notification title")
.setBody("My notification body");
notification.android.setChannelId("testNotification");
firebase.notifications().displayNotification(notification);

IBM Watson conversation training status API

I am using IBM Watson APIs to create intents and user examples and I want to know how to track the training status after creating a new intent and user examples.
To track the status from within the UI, open the "Try it out" panel. It will display "Watson is training". When complete it will stop.
Programatically, you can use the Workspace API to query the workspace. For example in Python.
from watson_developer_cloud import ConversationV1
url = "https://gateway-fra.watsonplatform.net/conversation/api"
username = "USERNAME"
password = "PASSWORD"
workspace_id = '2d5e7dd4-19fe-4ab3-9c3e-f2eff48c9ca4'
conv = ConversationV1(
username=username,
password=password,
version='2017-05-26',
url=url
)
response = conv.get_workspace(workspace_id=workspace, export=False)
print('Status is: {}'.format(response['status']))

onCreate send email to self in AppMaker?

Still learning about app maker and found this presentation at Google I/O '17 "Build Powerful Custom Apps Fast with App Maker on G Suite"
At timestamp 15.24 sec some code is shown on the screen showing how to send an email to yourself once someone creates a new item can.
https://youtu.be/Q84HQgI3Dd8?t=15m27s
Question
Can anyone advise where and how this code can be implemented its pretty cool and would be a great feature to add when a record is created
Thanks in advance and no worries if you cant help
You are looking for model events:
https://developers.google.com/appmaker/models/events
In App Maker models typically have onCreate, onSave, onLoad, onDelete events. It is the best place to handle email notifications. Here is a link to App Script email API:
https://developers.google.com/apps-script/reference/mail/mail-app
I strongly recommend you to go to the Codelab for App Maker. The section Building a form to send an email describes the whole process.
The steps to highlight are:
Step 11 - Set the onClick property of the button as a custom action with the code:
var widgets = widget.parent.descendants;
var to = widgets.To.value;
var subject = widgets.Subject.value;
var msg = widgets.Msg.value;
widgets.EmailStatus.text = 'Sending email...';
SendEmail(to, subject, msg)
Step 13 - Add the following ClientScript code:
function clearEmailForm(){
var formWidgets = app.pages.Basic.descendants;
formWidgets.EmailStatus.text = "";
formWidgets.Msg.value = "";
formWidgets.To.value = "";
formWidgets.Subject.value = "";
}
function SendEmail(To, Subject, Msg){
var status = app.pages.Basic.descendants.EmailStatus;
google.script.run.withSuccessHandler(function(result) {
status.text = 'Email sent...';
clearEmailForm();
})
.SendEmail(To, Subject, Msg);
}
Step 14 - Now add the corresponding code to the ServerScript.
function SendEmail(to, subject, msg){
MailApp.sendEmail(to, subject , msg);
}

Logout Firebase doesn't really work

I become crazy with a bug I have on my app.
I use the new Firebase to authenticate a user + Firebase DB
2 ways to signup/signin: Email or Facebook.
In my App, I have a logout button with the simple command:
try! FIRAUTH.auth()!.signOut()
self.performSegueWithIdentifier("firstScreen", sender: self)
works fine.
On a same iPhone, my test:
Login with Facebook
add datas to my app (firebase database)
Log Out
Login with an email account different of email used by Facebook
I retrieve the exact same datas that I had with my profile account.
like if I wasn't really logged out.
I Have to kill the app after logout to have the datas corresponding to the account I use.
Do you have any idea ?
What's happened exactly when I kill the app task ?
Thanks a lot for your answer.
I dealt with that same issue before, the problem is when you log out of firebase you also have to logout of facebook.
try! FIRAUTH.auth()!.signOut()
let loginManager = FBSDKLoginManager()
loginManager.logOut()
self.performSegueWithIdentifier("firstScreen", sender: self)
If you don't you will keep getting the same data back when you log in.
Thanks Justin but unfortunately it's exactly the same issue with your solution.
Maybe I am wrong on my AppDelegate, where I check if the user is connected when he leaves the App:
//check if user has a currentUser ID
//if Yes, we check if he has a username
//if Yes, he goes to vc (first viewcontroller)
//if not, he geos to the vc2 where he chooses a username
if ((FIRAuth.auth()!.currentUser) != nil){
userID = String(FIRAuth.auth()!.currentUser!.uid)
ref.child("Users").child(userID).child("name").observeSingleEventOfType(FIRDataEventType.Value, withBlock: { (snapshot) in
if (snapshot.value as? String == ""){
self.window?.rootViewController = vc2
}else{
self.window?.rootViewController = vc
}
})
}

Resources