So I've checked the internet for answers but I'm not finding one's that are useful enough to help with this.
So my intent code to start video through the MainActivity.Java is this:
case R.id.button3:
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(getString(R.string.Focus)), "video/*");
startActivity(Intent.createChooser(intent, "Choose an External Player"));
break;"
I wanted to know how I could automatically load up a subtitle through a URL so I can watch my videos with subtitles.
The external video I use is MX Player.
Any help would be appreciated.
The help page for doing this is at https://sites.google.com/site/mxvpen/api.
You basically add an extra to the intent with the string "subs" and then a parcelable array of subtitle file names.
Related
I have a weird problem, I am playing a video file from local storage, if the video name is "test#.mp4" it does not work and shows "media not found" toast, if it's "test.mp4", it works fine, no idea where is the problem.
basically if the name has "#" anywhere, the video does not play.
Here is my code
String item = names.get(itemPosition); // file name eg. test#.mp4
Uri uri = Uri.parse(context.getExternalFilesDir(null).getAbsolutePath() + "/MyFiles/"+item); // path to file
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setDataAndType(uri, "video/*");
context.startActivity(intent);
The answer is that I needed to use FileProvider, I have no idea why my earlier method was working and sometimes not.Also because the original documentation is so confusing, I used this answer, I took a look at the actual Uri and everything made sense now! android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()
I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.
This question already has answers here:
Android ACTION_SEND event: "messaging failed to upload attachment"
(2 answers)
Closed 5 years ago.
I am trying to create a Sharing Intent for an Android App to share images to other apps. However, I'm getting this really weird result when implementing this feature.
I have a share button that when I click on the button, it runs the following method:
private void shareIntent() {
Uri currUri = Uri.parse(data.get(pos).getUrl());
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, currUri);
sharingIntent.setType("image/jpg");
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.share_to)));
}
data.get(pos).getUrl() returns the URL of a custom class I made that implements Parcelable, and when printing it out, it returns a directory like the following: "/storage/emulated/0/Pictures/primitive/Primitive-79538313.jpg"
The intent works at first, opening the sharing menu. However, when I click on most applications, it either crashes the application or it gives an error... except with Google Photos, which uploads the photo properly to the gallery.
Firstly, I'm wondering what I'm doing wrong to cause this issue in the other apps. Also, I'd like to know if someone has an explanation as to why only Google Photos allows the sharing feature to work, while many of the other apps I've tested do not.
For reference, here are some examples I've run with the sharing intent. When I try to share the image, it crashes Hangouts. It gives a "failed to load image" error message in Snapchat, "Unable to share file" in Slack and Gmail, "Upload was unsuccessful" in Drive, "Messenger was unable to process the file" in, well, Messenger, and "Couldn't load image" in GroupMe. It doesn't load the image in Facebook but doesn't crash nor give an error.
Thank you for any help or feedback you can provide!
EDIT:
This seemed to work without trying to get around App Permissions:
private void shareIntent() {
File imageFile = new File(data.get(pos).getUrl());
Uri uriToImage = FileProvider.getUriForFile(
this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(DetailActivity.this)
.setStream(uriToImage)
.getIntent();
shareIntent.setData(uriToImage);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Thank you to everyone that responded!
Change your code to this
private void shareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jepg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+data.get(pos).getUrl()));
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Add this code in your activity onCreate()
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
I am currently in the process of creating direct intents to a selection of popular platforms in an Android app to share some text. I am currently trying to get a direct intent working with LinkedIn.
I have currently got a direct intent working for Twitter like so:
shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.twitter.android",
"com.twitter.android.PostActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivityForResult(shareIntent, 9);
What I need now is the same for LinkedIn. So far I know the base package for LinkedIn after searching on the internet. That being "com.linkedin.android" (Please correct me if this is wrong). However, the key part I am missing is the name of the class that deals with sharing in the LinkedIn app. I.e. com.linkedin.android.?.
I managed to find the intent by extracting the LinkedIn Manifest file from the APK.
The class name is: com.linkedin.android.home.UpdateStatusActivity
My code for anyone interested is:
if(Utils.doesPackageExist(getSherlockActivity(), "com.linkedin.android"))
{
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.linkedin.android",
"com.linkedin.android.home.UpdateStatusActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
startActivity(shareIntent);
}
else
{
Toast.makeText(getSherlockActivity(), "Please install the LinkedIn app to share your result", Toast.LENGTH_LONG).show();
}
Credit to Ryszard Wiśniewski for his work on http://code.google.com/p/android-apktool/
As of my writing, the new class name is:
com.linkedin.android.infra.deeplink.DeepLinkHelperActivity
So all together:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.linkedin.android",
"com.linkedin.android.infra.deeplink.DeepLinkHelperActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
startActivity(shareIntent);
It is com.linkedin.android.publishing.sharing.ShareActivity , you can download this app and see what is the current Activity name thats running on your phone https://play.google.com/store/apps/details?id=com.willme.topactivity ... But com.linkedin.android.publishing.sharing.ShareActivity seems its a private class and you can't access as you access Twitter
How to you make it so if a user does something, it asks them how they want to do it and it brings them to that application? Like if you go "Share" a photo or video it pops up a list with all apps that can do that for you like facebook or text or email , ect.? I am asking how to have my app use other apps, not them use mine.
You do this by targeting the intent filter that the other apps use.
For example, if I want to share a picture, I can do this:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/test.jpg"));
startActivity(Intent.createChooser(share, "Share image"));
Then you will get a popup to choose the app to use for this action.