Looking to handle a deep link from the Google Assistant. As I only have an emulator at the moment I am having trouble testing it (from what I have read it requires a real device). That said, I was wondering if I am handling it the correct way. I am unfamiliar with Kotlin and my code was turning into Spaghetti trying to integrate, so I put this together in my existing launcher activity just to try and get it bootstrapped for now. The manifest and actions.xml were set up like the fitness app tutorial.
Am I doing this correctly?
if (mAuth.getCurrentUser() != null) {
data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
uriData = data.toString();
containsStart = containsIgnoreCase(uriData,"start");
containsRun = containsIgnoreCase(uriData,"run");
if(containsStart && containsRun) {
Intent intent = new Intent(getApplication(), RunActivity.class);
intent.putExtra("runStart", true);
startActivity(intent);
}
}
else {
checkUserAccType();
}
//Else, if there is no current user, start the Authentication activity
}
A few observations and recommendation about your code:
Instead of using containsIgnoreCase uses getPath() and match the path. See example.
Also, for the activity parameter use URL query param instead of containsIgnoreCase. See example
Starting the activity or fragment. I assume startActivity and checkUserAccType will handle that part. See example.
// Else... section should go one line below.
Authentication. It looks fine. And it seems you're using Firebase by the getCurrent method signature. See example
Related
I have an application at the Google Play and there are already a few hundred of users.
Now, I'm working on an update that will allow users to share user-to-user content via Firebase Dynamic Links.
In order to do so, I created a subdomain and all the required things and I added this code:
FirebaseDynamicLinks.getInstance()
.getDynamicLink( getIntent() )
.addOnSuccessListener( this, pendingDynamicLinkData -> {
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String bookID = deepLink.getQueryParameter( "id" );
if (bookID != null) {
startBookDetailActivity( bookID );
}
}
} )
.addOnFailureListener( this, e -> {
}
);
However, the users who already have the app installed on their phone don't have this piece of code in their application which means that if they click on the dynamic link it won't do the job.
Is there any other way I can handle the dynamic link for the period until all users get the latest version?
Thank you
You could have the user copy and past the code into the app but ultimately, this also requires that the app is updated to do so.
Perhaps you could use a cloud function that would return the data in the browser rather than the app, you could do this with a button that appears after a second and manually invoke the call.
But it might just be easier to encourage users to update and implement a callback system using real-time or firestore as a user inbox system for this kind of edge case.
I'm developing an android app and part of it needs to read WhatsApp messages by the notifications and analyze them.
I'm using a NotificationListenerService and it is working, however, I'm having a problem that notifications are being "analyzed" twice when I get the notification and then get a Message from other chat.
What I want is to analyze each message (Notification) once.
I already tried to save the notification sortKey or the StatusBarNotification key in a HashSet and then check, if it already contains the key every time, however that does not work.
Here is the code that in onNotificationPosted function -
String pack = sbn.getPackageName();
if (pack.equals("com.whatsapp")) {
Bundle extras = sbn.getNotification().extras;
if (extras.getCharSequence("android.text") != null && extras.getString("android.title") != null) {
if (sbn.getNotification().getSortKey() != null) {
String title = extras.getString("android.title");
String text = extras.getCharSequence("android.text").toString();
//Checking if it's from specic group and analyzing the message and
//doing what needs to be done, not related to the problem.
}
}
}
The result I want is that every notification will be analyzed once and not get posted again if some other messages arrive in other chats
Without knowing the inner workings of WhatsApp, it's hard to tell what you should exactly do, because it appears they reuse Actions/Extras for various things (which makes sense anyway).
In this case though, you could keep a list/map of the ones you've already "analyzed" and if you get it again, discard it.
Since my Google Maps app updated recently, now version 10.11.1, the following code does not show the label as expected, documented, and previously working:
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:38.8951,100.0364?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
And neither does this version (with 0,0 immediately after geo:):
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
Neither does the example code in the official documentation show a label:
// Display a label at the location of Google's Sydney office
Uri gmmIntentUri = Uri.parse("geo:0,0?q=-33.8666,151.1957(Google+Sydney)");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Update: Scheduled to be fixed in v11.12 perhaps before the end of January 2022.
No solution still even with latest map update 10.12.1 the label still does not show even if the documentation still says it should
I've created an issue on Google's Issue tracker: https://issuetracker.google.com/issues/129726279
hopefully we'll have some information shortly.
Per Google, it's a bug in the Google Maps app. It's fixed in version 11.12.
I think we are going about it the wrong way here. If I was Google, I would also feel insecure about allowing developers to post directions with an abstract destination label, I am sure they never plan to fix this.
I recommend the following solution according to Google's new standards. https://developers.google.com/maps/documentation/urls/android-intents:
https://www.google.com/maps/dir/?api=1&destination=LATITUDE,LONGITUDE
If you look at most apps these days, including the ones I have built, this allows us to post a LAT/LONG for the user to go to with Google's own Address values built in as the destination label.
To actually launch the Google Maps application, simply launch a web intent, I use the application context in this case.
fun startGoogleMaps(context: Context, lat: Double, long: Double) {
startWebBrowser(
context,
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=$lat,$long")
)
}
fun startWebBrowser(context: Context, link: Uri?) {
if (link != null) {
val webIntent = Intent(Intent.ACTION_VIEW, link).apply {
addFlags(FLAG_ACTIVITY_NEW_TASK)
}
if (webIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(webIntent)
}
}
}
I have implemented Google Maps in my App and doing reverse geocoding when clicking on map.Im using This API. but it gives me more than one result on Single tap. I know why Google behave like this.
Then I look into PlacePicker widget for Android, but Im unable to use that widget without opening another Map screen to pick place.
What I want is that I want to use my Google Map screen to get tapped place instead of opening PlacePicker screen. I just want PlacePicker work with my implemented Map i.e want PlacePicker to respond map click and give place without opening widget if this is not possible then inform me about other solution to get exactly one and correct place on Map tap? Thank you in advance
Updated
Why Im getting closed vote for question? it is not too broad? Simply,I want to know whether is it possible to use Google Map (MapView|SuportFragment) as PlacePicker's main screen. Have look code below
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
// I don't want this line, Don't want PlacePicker to open another Map Screen to allow user to pick place.
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
now look at below code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
above code is executed when user pick a place from PlacePicker screen and that screen returns a Intent with picked place. Is there any way to make that type of 'Intent' on Google Map tap with lat,lng? so that I could get Place detail. I don't want to user reverse geocoding as it gives me many results.
I Donot know anything about the google geo api or PlacePicker api.
The google independent android standard way would be to use "ACTION_PICK" with a geo uri.
For more infos see https://github.com/k3b/k3b-geoHelper/wiki/Android-Geo-howto.
This only works if you have installed a geo-pick-aware app that supports geo-pick.
Note: you do not have to use the lib. All you need to do is to decode the geo-uri returned by activity result
I have found solution to my problem, To get rid of reverse geocoding to many results and to get clicked place I use following code
googleMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() {
#Override
public void onPoiClick(PointOfInterest pointOfInterest) {
String SS="";
isPOI=true;
poiPlaceID=pointOfInterest.placeId;
// Then using Google PlaceDetail API with placeId, It gives me exact Location click
}
});
I am trying to add a button in my application that starts Google Voice Typing (or the default speech recognition). I have tried following this tutorial. This tutorial is incredibly confusing to me. I imported the .jar, and added the necessary permissions, services, and activities to my Manifest. But I can't seem to figure out how to "put it all together". I'm wondering:
Am I supposed to call the inputMethodService from my button click in my Main Activity? Or does my inputMethodService essentially become my Main Activity?
What does IME mean? I tried to Google it, but the definitions it gave me didn't help my understanding.
When I try to copy and paste the whole DemoInputMethodService code into my current activity, I get an error saying I cannot extend InputMethodService inside of this activity. (Which leads back to to ask question one.)
How can I get this to work?
If you want to follow the tutorial that you mention then you need to implement an IME (input method editor) first, see http://developer.android.com/guide/topics/text/creating-input-method.html
This IME can have a regular keyboard look-and-feel or contain just a microphone button.
The user of your app will first have to click on a text field to launch the IME. (Note that there can be several IMEs installed on the device and they have to be explicitly enabled in the Settings.) Then the user will have to click on the microphone button to trigger the speech recognition.
The tutorial provides a jar that lets you directly call Google's recognizer. It would be nicer if instead you called the recognizer via the SpeechRecognizer-interface (http://developer.android.com/reference/android/speech/SpeechRecognizer.html), this way the user can decide whether to use Google's or something else.
The SpeechRecognizer is given a listener which supports the method onPartialResults, which allows you to monitor the recognition hypotheses while the user is speaking. It's up to you how you display them. Note however that the specification of SpeechRecognizer does not promise that this method gets called. This depends on the implementation of the recognizer service. Regarding Google's implementation: what it supports keeps changing unannounced, it does not have a public API nor even release notes.
You might be able to reuse my project Kõnele (http://kaljurand.github.io/K6nele/about/), which contains two implementations of SpeechRecognizer and an IME that uses them. One of the implementations offers continuous recognition of arbitrarily long audio input, using the Kaldi GStreamer server (https://github.com/alumae/kaldi-gstreamer-server). You would need to set up your own instance of the server porting it to the language that you want to recognize (unless you want to use the Estonian server that Kõnele uses by default).
Voice recognition samples are found where you have the android SDK..
example:
$ find $SDK_ROOT/samples -name *recogni*
./android-19/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-19/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-19/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-18/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-18/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-18/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-21/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-21/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-21/legacy/ApiDemos/res/layout/voice_recognition.xml
any one of the services should help show how to do a RecognizerIntent
The "APIDemo" seems to include use of a RecognizerIntent. check the source for that one. Otherwise look into the services and carve them up into an intent.
I had the same issue, but after a long time looking for continuous voice dictation on an activity, I solved that problem using pocketsphinx.
I couldn't find the way to integrate Google Voice Typing on an activity, just on an input method by following that tutorial. If it confuse you, just download this demo and modify it.
Good Luck!
You can trigger an intent from a button listener
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
And the result can be get from
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
Refer this link for more info.