How to send a text query to Google Assistant from Android app - android

I'm trying to start Google Assistant and send a text question (not voice) from my app when I press a button. For example: I click a button, and the Google Assistant answer to my question "How is the weather today?".
Is this possible?
EDIT:
When I press a button I want the Google Assistant to do some actions and give a spoken feedback.
For example: "Read the weather for tomorrow and set the alarm to 6.30 am".

It looks as though you can reference it from a direct package class name.
String queryString = "How is the weather today?";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox",
"com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra("query", queryString);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

If you're already using the Assistant SDK, it's pretty simple. Just replace AudioInConfig with a text query. Here's how I do it:
AssistConfig config = AssistConfig.newBuilder()
.setTextQuery("Your text query goes here!")
//.setAudioInConfig(audioInConfig)
.setAudioOutConfig(audioOutConfig)
.setDeviceConfig(deviceConfig)
.setDialogStateIn(dialogStateIn)
.setScreenOutConfig(screenOutConfig)
.build();
AssistRequest request = AssistRequest.newBuilder().setConfig(config).build();
Then send the request to the server over gRPC and you'll get a spoken response back.

Related

how can I redirect the user to Setting -> Security -> Notification Access in Flutter?

6
I'm currently developing an app for Android that uses the NotificationListenerService, which requires that the user will enable notification access for my app under Setting -> Security -> Notification Access.
My question is that can I redirect the user to this place so they will enable it? So far I only managed to direct them to Setting -> Security window.
Also, is it possible to first check if the user enabled notification access for my app already and only then redirect them?
For Flutter
After a long search, I found the solution that will show the intended notification settings.
This is only for Flutter.
I found an app_settings plugin. Just add it in pubspec.yaml and install it.
After that just one line of code.
RaisedButton(
onPressed: () {
// AppSettings.openLocationSettings();
AppSettings.openNotificationSettings();
// openWIFISettings();
},
)
For Java
To open the settings for a specific channel, you can use ACTION_CHANNEL_NOTIFICATION_SETTINGS:
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, yourChannelId);
startActivity(intent);
Using ACTION_APP_NOTIFICATION_SETTINGS will open settings of list all channels of the app:
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
startActivity(intent);
For Notification check, you can use "areNotificationEnabled" method.
You can read at below doc/
https://developer.android.com/reference/android/support/v4/app/NotificationManagerCompat.html#areNotificationsEnabled()

How to open Android Outlook application from an external one

I'm currently developing an Android application in order to display home screen widgets. Those ones are related to Microsoft Outlook (Events + Messages) in order to show incoming events and unread new messages in a kind of dynamic tiles.
The Msal graph library helps me a lot to authenticate and retrieve in formations which contains an identifier for each event / message results
But now I want to know if the outlook application is installed on the user device and if there is a way to open Outlook when the user click on the widget. Moreover if the user can open the corresponding clicked event or message with the identifier.
For example the Event widget currently displaying a birthday event. The user click on it. Then it opens Outlook and display directly that birthday event.
Regards
I don't think this is officially documented somewhere. But here's what you can do to find out about it.
You can list all Microsoft applications installed on your device...
val packages = context.packageManager
.getInstalledApplications(PackageManager.GET_META_DATA)
for (info in packages) {
if(info.packageName.startsWith("com.microsoft", true)){
Log.d("package name:" + info.packageName)
Log.d("Launch Activity: " + context.packageManager.getLaunchIntentForPackage(info.packageName))
}
}
Take a note of the "launch intent" displayed in the LogCat. You can use that to launch Outlook. Just make sure you don't hard-code those values because Microsoft can change those values at any point, for example the activity class can change. So, instead of doing this...
context.startActivity(
Intent().apply {
action = Intent.ACTION_MAIN
addCategory(Intent.CATEGORY_LAUNCHER)
setPackage("com.microsoft.office.outlook")
component = ComponentName("com.microsoft.office.outlook", "com.microsoft.office.outlook.MainActivity")
}
)
Do this...
context.startActivity(
Intent().apply {
action = Intent.ACTION_MAIN
addCategory(Intent.CATEGORY_LAUNCHER)
component = ComponentName(
outlookLaunchIntent?.component?.packageName,
outlookLaunchIntent?.component?.className
)
setPackage(outlookLaunchIntent.package)
}
)
Also, remember that getLaunchIntentForPackage and component can return null, so make sure you check for null values properly
I am relaying a suggestion from a couple of internal folks:
Please try to open the event using one of the following URLs:
ms-outlook://events/open?restid=%s&account=test#om.com (if you have a regular REST id)
ms-outlook://events/open?immutableid=%s&account=test#om.com (if you are using an immutable id)
Since immutable IDs are still in preview stage in Microsoft Graph, and customers should not use preview APIs in their production apps, I think option #1 applies to your case.
Please reply here if the URL works, or not, and if you have other related questions. I requested the couple of folks to keep an eye on this thread as well.
Well, i managed to open the outlook android application with the help of your code #Leo. As im not developping with Kotlin, ill post the JAVA code below :
Intent outlookLaunchIntent = context.getPackageManager().getLaunchIntentForPackage("com.microsoft.office.outlook");
if (outlookLaunchIntent != null) {
context.startActivity(outlookLaunchIntent );
}
Below code to open event/message in a web browser provided by webLink property of the graph API. (I only test for event and the url provided not working. Ill post a new issue on StackOverFlow for that but you already see the issue over there : https://github.com/microsoftgraph/microsoft-graph-docs/issues/4203
try {
Intent webIntent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(calendarWebLink));
webIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(webIntent);
} catch (RuntimeException e) {
// The url is invalid, maybe missing http://
e.printStackTrace();
}
However im still stuck on the decicive goal of my widget item click which is to open the relative event/email in the Microsoft Outlook Android application.
Microsoft Outlook Android app contains widgets which can achieve what im looking for. So i wonder if it is possible to list its broadcast receivers.
The best thing i found is an old manifest for that app but it doesnt help me.
https://gist.github.com/RyPope/df0e61f477af4b73865cd72bdaa7d8c2
Hi may you try to open the event using one of the url:
ms-outlook://events/open?restid=%s&account=test#om.com (If the
user is having rest id)
ms-outlook://events/open?immutableid=%s&account=test#om.com (If
the user is having immutable id)

OnProvideAssistDataListener example

Can someone please provide an example for a real case where I might need to use OnProvideAssistDataListener. I can't seem to wrap my head around it. I look at the source code, and then I look online. Someone online says
Application.OnProvideAssistDataListener allows to place into the
bundle anything you would like to appear in the
Intent.EXTRA_ASSIST_CONTEXT part of the assist Intent
I have also been reading through the Intent Docs.
There is an Now On Tap functionality implemented by Google. By long pressing the Home Button, you will get some  information displayed on the screen.  The information you get depends on what you're viewing on your screen at that time. (for eg: Music app displays information about music on the screen).
To provide additional information to the assistant, your app provides global application context by registering an app listener using registerOnProvideAssistDataListener() and supplies activity-specific information with activity callbacks by overriding onProvideAssistData() and onProvideAssistContent(). 
Now when the user activates the assistant, onProvideAssistData() is called to build a full ACTION_ASSIST Intent with all of the context of the current application represented as an instance of the AssistStructure. You can override this method to place anything you like into the bundle to appear in the EXTRA_ASSIST_CONTEXT part of the assist intent.
In the example below, a music app provides structured data to describe the music album that the user is currently viewing:
#Override
public void onProvideAssistContent(AssistContent assistContent) {
super.onProvideAssistContent(assistContent);
String structuredJson = new JSONObject()
.put("#type", "MusicRecording")
.put("#id", "https://example.com/music/recording")
.put("name", "Album Title")
.toString();
assistContent.setStructuredData(structuredJson);
}
For more info refer https://developer.android.com/training/articles/assistant.html

Google Keep list note from inside your app

In my app, I am writing a functionality to share a shopping list to Google Keep. For this, I use the Intent.ACTION_SEND action and set the package to the one of Google Keep.
Everything works great, but I am wondering if it is possible to add an EXTRA parameter to the Intent telling Google Keep it must be displayed as a list with checkboxes, like it is possible to add extra event-specific extra's when creating a Calendar Event. Now, it is displayed as plain text.
Here is my code:
try {
Intent keepIntent = new Intent(Intent.ACTION_SEND);
keepIntent.setType("text/plain");
keepIntent.setPackage("com.google.android.keep");
keepIntent.putExtra(Intent.EXTRA_SUBJECT, "Shopping List " + recipe.getName());
keepIntent.putExtra(Intent.EXTRA_TEXT, "Flower\nyeast\nbutter\nalmonds");
startActivity(keepIntent);
} catch (Exception e) {
Dialogs.toastShort(this, "Google Keep is not installed on your device");
}
Now, I get this as result:
What, I want to get is this as result - without that the user has to select "show checkboxes" in the actionbar:
Thanks for your help.
Unfortunately, it's not possible. Google has not published an API for public nor 3rd party use. If you check out the http traffic you can see the underlying API but there's no real way to replicate it. Sorry

WebDialog.RequestsDialogBuilder does not actually send a request?

I am working on an app, which sends a request to the selected user. Am selecting the user through FriendPickerFragment(Android.Support.V4.App). I am successfully getting the list of friends I have selected on the "Done" button of the Picker fragment. Post that, I am trying to build a request dialog, which should not show up in my app, but should send the FB request to the selected friends. Here is my code:
Bundle bundle = new Bundle ();
bundle.PutString ("app_id", AppID);
var dialog = new WebDialog.RequestsDialogBuilder (this.Activity, Session.ActiveSession, bundle).SetMessage(user + " has invited you to join my application");
dialog.Build ();
The problem I am facing is that, the request is not actually sent. There is no exception either. I even implemented the call back:
public void OnComplete(Bundle bundle, FacebookException e)
but the execution does NOT go in the callback. What am I missing here ? Any help would be greatly appreciated.
Tried dialog.SetTo(userId) before build also....still not working...
Any suggestions ?
Well, according to the documentation for RequestDialogBuilder the method public WebDialog build(), the behavior you describe is by design. Quote:
"The dialog is not shown, but is ready to be shown by calling Dialog.show()"
It sounds like you do not want to show a dialog, but just want to send a request without any UI. You are using the wrong tool to do that. To send a request using a dialog, you have to show the dialog, and the user action is what causes a request to be sent. This doesn't require any special permission to be granted ahead of time, because it only sends a request if the user chooses to after your app opens the dialog.
There may or may not be a way to do what you want (send an app request without any user interaction) ... if there is a way, it will be along these lines:
use the Graph API, get a token with some permission that the user grants to your app. Here's a place to start looking:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/apprequests/

Categories

Resources