In my android app I'm recording an audio file which I then want to share to SoundCloud and GET the url of that. What's the best way to do so?
I can share through an explicit Intent but how can I get the track url then? shall I use the java wrapper to upload the audio?
File myAudiofile = new File("/path/to/audio.mp3");
Intent intent = new Intent("com.soundcloud.android.SHARE")
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(myAudiofile))
.putExtra("com.soundcloud.android.extra.title", "Demo");
// more metadata can be set, see below
try {
// takes the user to the SoundCloud sharing screen
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException e) {
// SoundCloud Android app not installed, show a dialog etc.
}
Refer:
https://github.com/soundcloud/android-intent-sharing/wiki/Explicit-intent-sharing
Related
I want to open chooser for both whatsapp and gb-whatsapp so the user can choose any of one from them. This code is only opening whatsapp only.
Intent intentWhatsapp = new Intent(Intent.ACTION_VIEW);
String url = "https://chat.whatsapp.com/JPJSkaiqmDu5gLKqUPAfMM";
intentWhatsapp.setData(Uri.parse(url));
intentWhatsapp.setPackage("com.whatsapp");
startActivity(intentWhatsapp);
To handle business whatsapp, GB-Whatsapp and normal whatsapp, the url scheme intent needs to be used, since the normal method of using package "com.whatsapp" only works for normal whatsapp.
Here's the code sample to handle gb, normal and business whatsapp :
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("whatsapp://send?phone="+ "+92300xxxxxxx" +"&text=" + URLEncoder.encode("Message\n", "UTF-8")));
context.startActivity(i);
} catch (Exception e){
Toast.makeText(context, "Whatsapp not installed!", Toast.LENGTH_LONG).show();
}
Simple answer you can't.
More detailed answer: You can only create an Intent targeting one specific app. I would suggest building a dialogue inside your app, showing the app images of whatsapp and gb-whatsapp, and then putting specific intents behind those two images so that it "looks" like the Android chooser.
I am working on my app which will show my website and i am getting intent error in my Android Webview app whenever I try to open Instagram profile. I want it to be open in my Instagram app can someone help me out by code please
Please help me out Click here to see the error I got
Seems that url you created could be invalid, try to create your intent with urls like these:
Uri uri = Uri.parse("http://instagram.com/_u/xxx");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
//instagram app exists on device
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
//instagram app does not exist on device, using browser
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
I am trying to sharing my data on Instagram but when I am shared my content on Instagram. I haven't gotten any success callback or when not shared then also not get failure callback. I am unable to found SDK for Instagram sharing as well as any API. Below I have mentioned my code by which I tried to sharing content on Instagram.
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Limit this call to instagram
share.setPackage("com.instagram.android");
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
try {
// Fire the Intent.
startActivityForResult(share, REQUEST_CODE);
} catch(ActivityNotFoundException e) {
// instagram not installed
}
As mentioned in Instagram docs. They didn't provide any callback to such sharing.
If your application creates photos or videos and you would like your users to share them using Instagram, you can use Android Intents to open your media in Instagram's sharing flow.
I have to share an image from my application to instagram. I have gone through Instagram developer documentation and there they mentioning only about sharing via Intent method, but what I need is I have to get a callback after posting successfully.
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
is there any way to do this ?
There are several options depending on their API. At first referring their Android Intents, that is a bad example IMHO, this is more or less the default way in Android how to share data. What you want is something more like to open just their app. For such cases is there the setPackage() option:
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Limit this call to instagram
share.setPackage("com.instagram.android");
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
try {
// Fire the Intent.
startActivityForResult(share, REQUEST_CODE);
} catch(ActivityNotFoundException e) {
// instagram not installed
}
Now for the case that instagram is not installed you are almost lost. If there is no other SDK there is nothing you can do.
A very complex workaround might be to upload the file to your own backend. Then open the browser to gain access to an oauth token to upload the image via your backend. However this is a quiet expensive solution which I would avoid.
I've written a small app to parse some RSS feeds from YouTube and launch videos selected by the user. To play the video, I'm using an intent:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(videoAddress);
In order to call the YouTube app, if installed on the device.
The problem I'm having is that, of the population of videos I am using in my app, about 90% of them display a 'Cannot play video' error message: "Sorry, this video cannot be played.". A few of them work just fine from my app. The videos that do not work will play fine in the YouTube app if searched for and launched entirely from within the YouTube app.
Has anybody seen this behavior, or does anybody have any ideas for things to try? Obviously the YouTube app launches videos in a slightly different way internally than it does from an Intent request, but I haven't a clue how to get to the bottom of it.
I have the same issue. Are you sure that all of the video play correctly from the youtube app? In my case, on an old G1, the videos I can't play from my app won't play even if searched from within the youtube app.
I think the video encoding is not supported in some case and/or the combination of a slow cpu and slow network make the video not playable.
I've read about people just refreshing many times untill the video starts playing... I guess in thier care it was a network/buffering issue.
More discussion here:
http://www.google.com.tw/support/forum/p/android/thread?tid=3a62cdf7188384af&hl=en
For this reason my App (similar to yours) got a lot of bed comments. I republished it only for Android >=2.1 and I now I have fewer bad feedback.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(YOUTUBE_URL)));
The above line of code works for my App.
What it basically does is lets Android handle the startActivity with available installed software on the device. Android in turn opens the IntentChooser and lets the user decide which appropriate software to use in this case a Browser and Youtube App to open the video.
Try it out and let me knwo if it works for you or f you have any other issues.
The most reliable method I have found for accessing youtube from an application is using the mobile site, try this instead (eg for searching):
String videoUrl = "http://m.youtube.com/#/results?q=ciaconna+bach";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(videoUrl)));
This solved the "Cannot play video' error message" that I was receiving.
I use this code:
String vid= Uri.parse(urlVideo).getQueryParameter("v");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + vid));
try{
startActivity(intent);
}
catch (ActivityNotFoundException ex){
Log.e(TAG, "Couldn't find activity to view this video");
}
May be works for you.
I have got the same problem only with HTC Hero 2.1. You can force the intent to launch the htc flash player instead of the Youtube app. With the flash player app I have not had any problem:
Uri uri = Uri.parse("vnd.youtube:" + videoUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
String availableFlashPlayer = availableFlashPlayer();
if (availableFlashPlayer != null) {
// launch the intent with the available flash player
intent.setPackage(availableFlashPlayer);
}
startActivity(intent);
The availableFlashPlayer method:
public String availableFlashPlayer() {
String availableFlashPlayer = null;
String FLASH_PLAYER = "com.htc.flash";
PackageManager pm = getPackageManager();
try {
ApplicationInfo ai = pm
.getApplicationInfo(FLASH_PLAYER, 0);
if (ai != null) {
availableFlashPlayer = FLASH_PLAYER;
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
return availableFlashPlayer;
}
You can also check the Adobe Flash Player:
String FLASH_PLAYER = "com.adobe.flashplayer";
Alternatively, you can force the intent to launch the Android Browser as follows:
Uri uri = Uri.parse(videoUrl);
String packageName = "com.android.browser";
String className = "com.android.browser.BrowserActivity";
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setClassName(packageName, className);
startActivity(intent);