Starting a Song from Spotify Intent - android

Is there anyway to start a Spotify Track from its URI ?
I've tried the following approaches but none of them work. When Spotify opens, it always lands in the Playlists page, instead of the track's player.
String spotifyTrackURI = "spotify:track:1cC9YJ8sQjC0T5H1fXMUT2";
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.spotify.mobile.android.ui");
// I've tried with Intent#putExtra()..
launchIntent.putExtra( SearchManager.QUERY, spotifyTrackURI );
// or with setData
launchIntent.setData(Uri.parse(spotifyTrackURI))
context.startActivity(launchIntent);
Thanks

Found the answer on the #spotify channel on Freenode (irc). Thanks everyone!
I'm putting it here for other people to know about:
// right click on a track in Spotify to get the URI, or use the Web API.
String uri = "spotify:track:<spotify uri>";
Intent launcher = new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
startActivity(launcher);

First one is for old Spotify version.
For new versions you can use the second.
In this way it will first try with old version, if it fails with an exception it try with the second one :)
try {
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.mobile.android.ui", "com.spotify.mobile.android.ui.Launcher"));
intent.putExtra(SearchManager.QUERY, artistName + " " + trackName );
context.startActivity(intent);
} catch ( ActivityNotFoundException e ) {
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.mobile.android.ui", "com.spotify.mobile.android.ui.activity.MainActivity"));
intent.putExtra(SearchManager.QUERY, artistName + " " + trackName );
context.startActivity(intent);
}

If you get playlist for Artist on Spotify app. You need to start following intent. You do not need to package name or activity of Spotify.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("spotify:artist:" + "ARTIST SPOTIFY LINK"));
startActivity(intent);

Related

Android Intent for deep-linking to Deezer Search

I am trying to perform a search on Deezer by sending the following intent:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.deezer.com/search/" + query));
this.startActivity(intent);
In a previous version the web browser opened with a link saying "Open in Deezer" (or the like).
But in the current version this doesn't work anymore.
Is there any way to open the Deezer app and perform a search?
I have already tried the following (without success):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://search/" + query));
this.startActivity(intent);
There are many deeplinks you can use to search for content inside the Deezer app. You do have the basic search like this :
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
But you can also be more precise :
// Search for an artist, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/artist?query" + query));
this.startActivity(intent);
// Search for an album, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/album?query" + query));
this.startActivity(intent);
// Search for a track, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/track?query" + query));
this.startActivity(intent);
I believe it should be
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
The scheme of the Uri needs to be deezer. You have set it as http.
Try this. This should work.

Chooser is not working

in my app i want to display the location using map and also browsers(i need to display what are all the browser that installed in the device.) using the Chooser.please any one help me to find a solution.Thanks in advance. and also i need to set that always just once button in it.....
String format = "geo:0,0?q=" + Double.toString(latter)
+ "," + Double.toString(longer) + "(" + sender
+ ")";
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(Intent.createChooser(intent,
"Complete action using"));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
Use the below link as an example to implement chooser in android https://github.com/iPaulPro/aFileChooser

Google Search for Android

I am trying to put a simple Google Search in my app. I found this code but it's not exactly what I am searching for. Below the search comes from a given url.
String url = "http://www.google.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
The thing is that I would like to get the search text from user and if possible without starting a new Activity like this one:
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
Get the text from the user and place that in the URI, then start the intent.
String url = "http://www.google.com/search?q=" + userText;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Start Google search query from activity - Android

I was wondering if there is an easier way (or any way) to start a Browser with a Google search query. For example user can select a certain word or phrase and click a button and the activity will start the browser with the Google search query.
Thank you.
The Intent class defines an action specifically for web searches:
http://developer.android.com/reference/android/content/Intent.html#ACTION_WEB_SEARCH
Here's an example of how to use it:
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, query); // query contains search string
startActivity(intent);
You can do this quite easily with a few lines of code (assuming you want to search Google for 'fish'):
String escapedQuery = URLEncoder.encode(query, "UTF-8");
Uri uri = Uri.parse("http://www.google.com/#q=" + escapedQuery);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Otherwise, if you would rather start up your own Activity to handle the browsing, you should be able to do so with a WebView: http://developer.android.com/reference/android/webkit/WebView.html
I think the better answer here is #zen_of_kermit's. It would be nice though, if Android allowed a user to provide the Search engine has an extra though for the ACTION_WEB_SEARCH, rather than just using Google.
the # gave me trouble:
Uri uri = Uri.parse("https://www.google.com/search?q="+query);
Intent gSearchIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(gSearchIntent);
I recently tried this. This appears to work fine. If any modifications to be done let me know as I am new to android development.
mEdit = (EditText)findViewById(R.id.editText);
in your click view,
String q = mEdit.getText().toString();
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);
String Search= null;
try {
Search= URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Uri uri = Uri.parse("http://www.google.com/#q=" + Search);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});

launch sms application with an intent

I have a question about an intent...
I try to launch the sms app...
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setType("vnd.android-dir/mms-sms");
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.setFlags(flags);
intent.setData(Uri.parse("content://sms/inbox"));
context.startActivity(intent);
so, you can see that I put too much things in my intent, but that's because I don't know how I can do...
Thank's
To start launch the sms activity all you need is this:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
You can add extras to populate your own message and such like this
sendIntent.putExtra("sms_body", x);
then just startActivity with the intent.
startActivity(sendIntent);
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
If android version is Kitkat or above, users can change default sms application. This method will get default sms app and start default sms app.
private void sendSMS() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); // Need to change the build to API 19
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "text");
if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else // For early versions, do what worked for you before.
{
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address","phoneNumber");
smsIntent.putExtra("sms_body","message");
startActivity(smsIntent);
}
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
That's all you need.
If you want to launch SMS Composing activity from some of your other activity and you also have to pass a phone number and SMS text, then use this code:
Uri sms_uri = Uri.parse("smsto:+92xxxxxxxx");
Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
sms_intent.putExtra("sms_body", "Good Morning ! how r U ?");
startActivity(sms_intent);
Note: here the sms_body and smsto: is keys for recognizing the text and phone no at SMS compose activity, so be careful here.
Here is the code that will open the SMS activity pre-populated with the phone number to
which the SMS has to be sent. This works fine on emulator as well as the device.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:" + phoneNumber));
startActivity(smsIntent);
In kotlin this can be implemented easily as follows:
/**
* If android version is Kitkat or above, users can change default sms application.
* This method will get default sms app and start default sms app.
*/
private fun openSMS() {
val message = "message here"
val phone = "255754......." //255 Tanzania code.
val uri = Uri.parse("smsto:+$phone")
val intent = Intent(Intent.ACTION_SENDTO, uri)
with(intent) {
putExtra("address", "+$phone")
putExtra("sms_body", message)
}
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT -> {
//Getting the default sms app.
val defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context)
// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
if (defaultSmsPackageName != null) intent.setPackage(defaultSmsPackageName)
startActivity(intent)
}
else -> startActivity(intent)
}
}
This is modified answer of #mustafasevgi
Use
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName("com.android.mms", "com.android.mms.ui.ConversationList");
I use:
Intent sendIntent = new Intent(Intent.ACTION_MAIN);
sendIntent.putExtra("sms_body", "text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Intent eventIntentMessage =getPackageManager()
.getLaunchIntentForPackage(Telephony.Sms.getDefaultSmsPackage(getApplicationContext));
startActivity(eventIntentMessage);
try {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:" + Uri.encode(number)));
smsIntent.putExtra("address", number);
smsIntent.putExtra("sms_body", message);
PackageManager pm = activity.getPackageManager();
List<ResolveInfo> resInfo = pm.queryIntentActivities(smsIntent, 0);
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("sms")) {
//Log.d("TAG", packageName + " : " + ri.activityInfo.name);
smsIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
}
}
activity.startActivity(smsIntent);
} catch (Exception e) {
// Handle Error
}
Best way of doing this.
You can open default sms App and pass details as below :
Note : If u want to send to many numbers, separate each number with ";" inside string
String mblNumVar = "9876543210;9123456789";
Intent smsMsgAppVar = new Intent(Intent.ACTION_VIEW);
smsMsgAppVar.setData(Uri.parse("sms:" + mblNumVar));
smsMsgAppVar.putExtra("sms_body", "Hello Msg Tst Txt");
startActivity(smsMsgAppVar);
|Or| Use this function :
void openSmsMsgAppFnc(String mblNumVar, String smsMsgVar)
{
Intent smsMsgAppVar = new Intent(Intent.ACTION_VIEW);
smsMsgAppVar.setData(Uri.parse("sms:" + mblNumVar));
smsMsgAppVar.putExtra("sms_body", smsMsgVar);
startActivity(smsMsgAppVar);
}
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//CHANGE YOUR MESSAGING ACTIVITY HERE IF REQUIRED
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body",msgbody);
sendIntent.putExtra("address",phonenumber);
//FOR MMS
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mms.png"));
sendIntent.setType("image/png");
startActivity(sendIntent);
The best code that works with Default SMS app is.
Uri SMS_URI = Uri.parse("smsto:+92324502****"); //Replace the phone number
Intent sms = new Intent(Intent.ACTION_VIEW,SMS_URI);
sms.putExtra("sms_body","This is test message"); //Replace the message witha a vairable
startActivity(sms);
Compose SMS :
Uri smsUri = Uri.parse("tel:" + to);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("address", to);
intent.putExtra("sms_body", message);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
The below code works on android 6.0.
It will open the search activity in the default messaging application with the conversations related to specific string provided.
Intent smsIntent = new Intent(Intent.ACTION_MAIN);
smsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
smsIntent.setClassName("com.android.mms", "com.android.mms.ui.SearchActivity");
smsIntent.putExtra("intent_extra_data_key", "string_to_search_for");
startActivity(smsIntent);
You can start the search activity with an intent. This will open the search activity of the default messaging application.
Now, to show a list of specific conversations in the search activity, you can provide the search string as string extra with the key as
"intent_extra_data_key"
as is shown in the onCreate of this class
String searchStringParameter = getIntent().getStringExtra(SearchManager.QUERY);
if (searchStringParameter == null) {
searchStringParameter = getIntent().getStringExtra("intent_extra_data_key" /*SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA*/);
}
final String searchString = searchStringParameter != null ? searchStringParameter.trim() : searchStringParameter;
You can also pass the SENDER_ADDRESS of the sms as string extra, which will list out all the conversations with that specific sender address.
Check com.android.mms.ui.SearchActivity for more information
You can also check this answer
For Kotlin simply do that:
val messageIntent = Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:03xxxxxxxxx"))
messageIntent.putExtra("sms_body", "Enter your body here")
startActivity(messageIntent)
on emulator this work for me
Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("sms_body", remindingReason);
startActivity(i);
Sms Intent :
Intent intent = new Intent("android.intent.action.VIEW");
/** creates an sms uri */
Uri data = Uri.parse("sms:");
intent.setData(data);
Either you can use this ,both are working fine on android above 4.4
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address","9212107320");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
or
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body","Body of Message");
smsIntent.setData(Uri.parse("sms:9212107320"));
startActivity(smsIntent);
You can use the following code snippet to achieve your goal:
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse("smsto:"+model.getPhoneNo().trim()));
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.putExtra("sms_body","Hello this is dummy text");
startActivity(smsIntent);
If you don't want any text then remove the sms_body key.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse("smsto:"+shopkepperDataModel.getPhoneNo().trim()));
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(smsIntent);
Works up to Android 11. (Supports all supported SDKs)
btnMessageTo.setOnClickListener {
val phoneNumber = "+8801234567890"
val intent = Intent("android.intent.action.SENDTO")
intent.data =
Uri.parse("smsto:" + Uri.encode(phoneNumber ))
startActivity(intent)
}

Categories

Resources