I'm trying to open a frontal camera on my device but nothing that I try works and the back camera is always opening. I'm using the LG G4 device.
File file;
try {
File dir = new File(Environment.getExternalStorageDirectory());
file = File.createTempFile("temp.png", dir);
} catch (IOException e) {
AndroidExceptionHandler.handle(e);
}
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(cameraIntent, REGISTRO_PONTO_IMAGE_CAM);
What I'm doing wrong?
You are assuming that an undocumented, unsupported Intent extra will be honored by all camera apps on all devices.
There are ~2 billion Android devices, made up of thousands of device models. Those device models will ship with hundreds of different camera apps. Users can also install camera apps themselves. Any of those hundreds of camera apps may be what handles your ACTION_IMAGE_CAPTURE request. And none of them have to honor an android.intent.extras.CAMERA_FACING extra.
You are welcome to put that extra on the Intent, and it is possible that there are camera apps that will pay attention to it. You should not assume that any camera will pay attention to it, and it will be up to the user to choose what camera to use for taking the picture.
Related
I´m trying to develop an App which can send an .APK file via Bluetooth to another device with an Insecure Rfcomm connection. I´m running self-coded apps on both devices. The apps are not the same but I can still set the UUID, Rfcomm Listener and so on, so the connection should work fine and because of the insecure rfcomm without any alert to accept the transfer. I´ve tried the BluetoothChat example from the Android developer page, but I´ve got problems with changing the code for my purposes. Can anyone give me some snippets of code or any link to an tutorial how to setup Apps for Bluetooth File transfer? Every useful stuff is welcome.
EDIT:
You could say I´m trying to develop an app, which can "update" another app on another phone by Bluetooth.
Thanks
This worked for me:
public void shareApk(Context context) {
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);//context.getPackageName() is used for send my app's apk, you can give package name which you want to share
File srcFile = new File(ai.sourceDir);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
share.setPackage("com.android.bluetooth");
context.startActivity(share);
//context.startActivity(Intent.createChooser(share, context.getString(R.string.share_using)));
} catch (Exception e) {
Log.e("ShareApp", e.getMessage());
}
}
What's new with duration limit of MediaStore in Android 7? There is nothing about it in documentation, but since sdk version 24 a device records a video without any limit.
final Activity activity = (Activity) context;
String controlId = videoInput.getControlId();
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (videoInput.getMaxDuration() > 0) {
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoInput.getMaxDuration());
}
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoInput.getRecordQuality().ordinal());
int requestCode = ActivityResultBus.getInstance().generateRequestCode(new SBundle(controlId));
activity.startActivityForResult(intent, requestCode);
I tested it on a real Motorola Nexus 6 with Android 7.0 and on virtual devices with 7.0 and 7.1.1. On previous versions all works as I want.
Mb something wrong with my extras bundle?
"There is no requirement for any camera app to honor EXTRA_DURATION_LIMIT. This is a request, not a command"
Any other way to limit the length of video ?
Not when you delegate the work to a third-party app. You are welcome to use the camera APIs and record the video directly yourself. Or, if your concern is not with the video on the device but some subset that you need to upload, look into how you can chop off the first 10 seconds of the video, and upload that piece.
This answer is directly compiled from this question : MediaStore.EXTRA_DURATION_LIMIT Not working Nexus Devices?
I am looking for viable ways to send a file from my android app to another android device that doesnt have my app installed.
Option 1. Via share intent: https://stackoverflow.com/a/16755810/1865583
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(picURI);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image"));
Issue regarding option 1:
I would love if i could specify the device i want to send this file to, in the intent parameters? I've searched online but cant find this option.
I've stumbled across this multiple times but it only works on particular devices as far people claim. https://evilzone.org/java/%28android%29-three-ways-to-send-data-over-bluetooth/
ContentValues values = new ContentValues();
String address = device.getAddress();
values.put(BluetoothShare.URI, Uri.fromFile(new File("somefile.mp3")).toString());
values.put(BluetoothShare.DESTINATION, address);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
Is there a working/tested way to specify the device the bluetooth will try to send the file too? (and pair by default if necessary)?
Option 2. Using Bluetooth sockets to control the file transfer :
I am actually quite interested in developing this options, but all the examples online go about sending files from client to server where both code bases are developed by me.
What i need is to connect via bluetooth to the other android bluetooth enabled device and initiate the file transfer? But i am unsure how to initiate this transfer or which protocols are used if any etc? How would you connect to the default bluetooth app to send it a file?
I've found some information that i thought using as starting point https://stackoverflow.com/a/17237945/1865583
The user talks about using 00001106-0000-1000-8000-00805F9B34FB (File transfer service) and starting a RfcommSocket for communication. Would this be the right way to go to communicate with bluetooth android apps for file transfer?
I have been working on an app that needs to launch the "Wireless Display" devices list screen in android 4.2+ devices and then i found an answer here.
Based on the answer, i used the intent with suggested action "android.settings.WIFI_DISPLAY_SETTINGS" and fired the intent like this:
try
{
Intent intent = new Intent(ACTION_WIFI_DISPLAY_SETTINGS);
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
} catch (ActivityNotFoundException e)
{
e.printStackTrace();
DialogUtils.showSimpleDialog(HomeActivity.this,"Sorry, Feature not available in your device, please upgrade to android 4.2+");
}
which is working great for most of the phones but Samsung.
In Samsung 4.2 and higher devices it throws "No such Activity found to handle the intent" error.
It looks like Samsung has its own wrapper over the default android SDK and they have changed the handling of this function, not sure how to find out what they have with it.
Any help regarding this is highly appreciated.
I think I have found the solution, just need to add below permission and it works:
<uses-permission android:name="com.android.setting.permission.ALLSHARE_CAST_SERVICE" />
This is simple enough on every other version of Android, including SenseUI 1.5.
//For Contacts
Intent pickIntent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
this.startActivityForResult(pickIntent, RESULT);
//For Phones
Intent pickIntent = new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI);
this.startActivityForResult(pickIntent, RESULT);
On SenseUI 2.1 (HTC Incredible) this shows a list of numbers (the URI number). So you get a list of 1-200 if you have 200 contacts. Selecting one of the contacts you can then gather all of the information needed.
Is there any good work around known?
Unfortunately, I do not have any solution for this issue, which also occurs on the HTC Desire, but would recommend to file a bug with HTC instead of figuring out workarounds, as this IMHO clearly is a bug in HTC's implementation.