I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.
Related
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, videoLink);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
I can send the link containing the video to someone on WhatsApp, however, I want to show the image of the video to the user on WhatsApp.
Is there a way to do this in java or kotlin
as in the picture
I am not sure what you're trying to do exactly but there are two options I can think of.
Firstly, if you're looking for something like what you have in the screenshot then no coding is required.
This is usually handled by Facebook when their bot scrapes the meta tags from the page that is shared.
If you wanted to accelerate this process you can manually put the link that you want to share in Facebook's Sharing Debugger and scrape it manually so that Facebook takes note of it.
Once that is done you can share the link and it should display video information including the image, title & description.
However, if you want to share only the video image/thumbnail you can do that as follows:
grab the video ID from the URL using REGEX or by taking a substring of the URL that holds the ID.
Plug that ID in one of the following URLs to get a link to an image that you can share instead of the video.
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/default.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
Thanks to #asaph for his details answer on getting Youtube thumbnail here
In my App I've integrated the OpenStreetMap, in which I've fetched both source and destination coordinates. I need to pass those coordinates to OpenStreetMap App using Intent class, for that I need Uri.
After searching 2 days long I got this Uri
http://www.openstreetmap.org/?mlat=latitude&mlon=longitude&zoom=12
which currently supports only one location but I don't want it.
Can anyone please help me with this? Thanks in advance...
Here is my code below
Intent sendLocationToMap = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://openstreetmap.org/?mlat=13.074847&mlon=80.271019&zoom=12"));
startActivity(sendLocationToMap);
I assume you are asking about routing. In that case the answer is yes, there are various online routers (for example GraphHopper, OSRM and MapQuest) as well as offline routers for OSM available. Many of these online routers provide GPX exports.
You need to use /directions endpoint.
Example (following intent will open www.openstreetmap.org website with route between two points):
http://www.openstreetmap.org/directions?engine=osrm_car&route=53.1855%2C18.0272%3B53.0915%2C18.0087
Intent sendLocationToMap = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.openstreetmap.org/directions?engine=osrm_car&route=53.1855%2C18.0272%3B53.0915%2C18.0087"));
startActivity(sendLocationToMap);
OsmAnd app doesn't support directions urls:
http://www.openstreetmap.org/directions?engine=osrm_car&route=53.1855%2C18.0272%3B53.0915%2C18.0087
http://maps.google.com/maps?daddr=53.0915,18.0087&saddr=53.1855,18.0272
OsmAnd will display only one geo point without route between them.
Source: https://github.com/osmandapp/Osmand/blob/master/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java
However Google Maps directions url:
http://maps.google.com/maps?daddr=53.0915,18.0087&saddr=53.1855,18.0272
is supported by Google Maps and HERE.
I've seen some URIs to start navigation but i'm not convince with it.
I used this URI which starts browser or google maps:
Uri u = Uri.parse("google.navigation:q=" + Uri.encode(o.getLocalization().noZipString()));
Intent in = new Intent(Intent.ACTION_VIEW, u);
getActivity().startActivity(in);
And this which starts google navigation:
Uri u = Uri.parse("http://maps.google.com/maps?daddr=" + Uri.encode(o.getLocalization().noZipString()));
Intent in = new Intent(Intent.ACTION_VIEW, u);
getActivity().startActivity(in);
Both methods works but the question is - will user be able to choose custom navigation if present on his phone or google apps are the only ones that will be launched this way? I'm not really sure, those strings don't look too universal but I'm not able to test it for now. I've seen navigation vendor who is posting his own custom URI scheme on he's site but I'm not going to search for custom URI for every single navigation on the market...
It strongly depends on the application itself. If the application defines that it can handle implicit intents such as those, Android will provide those as an option in the choose app dialogue.
And, only Android M has the ability to show which links an application can handle in the app settings pane, as far as I know.
See this android developer article on linking to other applications.
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.
I have added code to my casual game to share highest score through social networks, email, etc.
This is the text I send as defined on strings.xml resouce, for l10n:
<string name="game_sharing_score" formatted="false">
My new High Score on Gamename: %d\n
You can download Gamename from here:\n
https://play.google.com/store/apps/details?id=gamepackage
</string>
Please, note that Gamename and gamepackage are not the actual ones that I am using.
The code for sharing is the following one:
String shareScoreMsg = String.format(context.getString(R.string.game_sharing_score), highestScore);
Intent shareScoreInt = new Intent(Intent.ACTION_SEND);
shareScoreInt.setType("text/plain");
shareScoreInt.putExtra(Intent.EXTRA_TEXT, shareScoreMsg);
game.startActivity(Intent.createChooser(shareScoreInt, context.getString(R.string.game_sharing_score_title)));
game is an Activity, context is an Application context, game_sharing_score_title is the title of the activity "Share your score". Anyway there is no problem with the code it self, it is working fine for sharing through Google+, WhatsUp or Twitter, but when the user selects to share through FaceBook, the text is clipped and it publish only the last link, with the information and one icon image that FB gathers from Google Play, ignoring all the text before the link.
It is pretty clear that the problem is just with Facebook, no with the code or the string.
What I would like to find is some kind of workaround, if exists, to avoid these FB problems. To be honest, I do not like Facebook, but it is a social network with millions of people and I cannot simply ignore it on my game.
Thanks a lot in advance,
Create Facebook app on your account
After that, you get the App id.
Access all methods from Facebook API.