I'm using the ACTION_VIEW to stream/play a remote video file. When the video is done playing the video player closes automatically. How do I stop the video player from closing? Thanks.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(MimeTypeMap
.getFileExtensionFromUrl(scFile.getFileUrl()));
intent.setDataAndType(Uri.parse(scFile.getFileUrl()), type);
startActivity(intent);
In order to do this there would need to be a way to pass a "don't close" flag in the intent's data. I'm not aware that such a flag exists, so if you really need this behavior I think you will need to use the MediaPlayer class instead.
I found the solution in another question.
call a new video intent like this:
Intent intent = new Intent (Intent.ACTION_VIEW);
intent.setDataAndType (uri,"video/mp4");
intent.putExtra (MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
activity.startActivity (intent);
link to original question: Returning to Android app after external video player closes
Hi you can use it like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("add video url");
intent.setDataAndType(data, "video/mp4");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,false);
startActivity(intent);
Related
I am trying to access photo libraray in android device using this code:
txtSelectPhoto.setOnClickListener(v->{
Intent i = new Intent(Intent.ACTION_PICK);
i.setType("image/*");
startActivityForResult(i,GALLERY_CHANGE_PROFILE);
});
but when it opens it just gives me a blank screen of the device folders with no photos like this although there are photos on the device.. is there any way to solve this?
Remove setType() and instead pass a Uri in the Intent constructor, representing the collection that you want the user to pick from:
txtSelectPhoto.setOnClickListener(v->{
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GALLERY_CHANGE_PROFILE);
});
Or, keep the MIME type and switch to ACTION_GET_CONTENT:
txtSelectPhoto.setOnClickListener(v->{
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("image/*");
startActivityForResult(i, GALLERY_CHANGE_PROFILE);
});
When I try to make a call from my app using
intent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode));
startActivity(intent);
I get the option
I want to programmatically choose the dialer that the user will use to make the call. I want the user to automatically use Phone (the original dialer) instead of Skype or any other option.
From googling, I found this option below but it only allows the developer to make the user choose the developer's own app as a default dialer. I want to programmatically ask the user to choose the original phone's default dialer "Phone" so that the user is no longer asked the question.
From google, I found this link: Programmatically change the "Use by default for this action"
which has this option:
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
} else {
Log.w(getLocalClassName(), "No Intent available to handle action");
}
But what I want is a bit different.
Use the below code:
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
it is working for me
Try This
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + "mobilePhone"));
context.startActivity(intent);
I'm developing an application that displays .dxf files (using Kabeja library). I've done all that part and everything works just as I wanted to. Problem is, I need to have a button that opens a file browser so the user can import his own .dxf from the sd card or local storage. It needs to filter files to only display .dxf so no other extension can be imported. I have absolutely no idea how to do this, nor to make a basic file browser. Could you help me getting on the right track ?
Thanks
Try this
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, 1);
}
And if you want to enforce an app chooser
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
Intent chooser = Intent.createChooser(sendIntent, "Title");
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(chooser, 1);
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*"); // all images
//intent.setType("image/png"); // only pngs
startActivityForResult(intent);
And get response in onActivityResult method. More details in documentation.
I want to share my image into instagram story. Now I can open istagram easily like this , but this code show me the page that we share photo.
I dont want this one, I want to open instagram story page just.
Here with this code:
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
File media = new File(path);
Uri screenshotUri = Uri.fromFile(media);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
sharingIntent.setPackage("com.instagram.android");
startActivity(sharingIntent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(SavedActivity.this, "برنامه اینستاگرام یافت نشد.", Toast.LENGTH_LONG).show();
}
Is it possible to share directly into story of instagram?
This is not possible (not to mention bad practice).
You can only dictate which application(s) can handle your intent, not what they do with that intent once it is received.
It is also not good practice to hardcode the application package you want to send to within your codebase (i.e. "com.instagram.android"). The Android documentation as well as the Instagram developers documentation recommends that you use the standard "chooser" pattern to share photos. In which case, the user will decide which app to share the photo with.
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(type);
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
share.putExtra(Intent.EXTRA_STREAM, uri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(share, "Share to"));
} else {
Toast.makeText(this, "No application to share with", Toast.LENGTH_SHORT).show();
}
Unless this is a personal project (it will not make it to the Google Play Store), I suggest you stick to the above pattern.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(String.valueOf(dest));
sharingIntent.setType("video/*");
sharingIntent.setPackage("com.instagram.android");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share Video "));
I hope it helps someone .
The problem I have is that when this intent is started there are no apps to show. Why is that? I need all apps to be visible since onClick the button will go to any app the user wants to and save it (use this app as default). What could be the solution?
Intent intent = new Intent(Intent.ACTION_ALL_APPS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooser);
Try-
Intent pickIntent = new Intent(Intent.ACTION_ALL_APPS);
pickIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
pickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(pickIntent);
This will give you all the apps in a list-
Intent pickIntent = new Intent(Intent.ACTION_MAIN, null);
pickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List pkgAppsList = getPackageManager().queryIntentActivities( pickIntent, 0);
Log.d(MainActivity.class.getSimpleName(), pkgAppsList.toString());
//startActivity(pickIntent);
pkgAppsList will have the list of all the applications. Hope this solves your problem.