Pixel 3 help Android - android

Ok This might seem like a dumb question but I'm not finding an answer.
I use to program for my old samsung S3. It's basically the device I learned to code for because it was all I had. But all the coding I was doing was old code I learned off Youtube etc.. as I'm self taught.
I recently invested in myself to learn some more modern code and to do things I couldn't do with my old equipment and I have run into trouble.
I have managed to fix some things like my retrofit and Picasso not working, because of a line of code missing in the manifest, but I am stuck when it comes to the Camera app as my code doesn't work on my pixel 3 but does work on my S3.
So I have a few questions that maybe someone can help answer for me.
so my 1st question is involving saving my pictures.
private File getfile () throws IOException {
File propicturefolder = new File("sdcard/camera_pro");
if (!propicturefolder.exists())
{
propicturefolder.mkdir();
}
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String prepend = "Picture_" + timestamp + "_";
File image_file = File.createTempFile(prepend, ".jpg", propicturefolder);
return image_file;
}
As you can see in my first bit of code I'm saving the picture to the SD card. But apparently a Pixel 3 doesn't have a SD card. So I don't know where to save it? There aren't really any examples out there that explain where this goes for a pixel 3. All my old examples go to the SD card.
I have tried to google an answer for this but nothing comes up but reviews of the Pixel 3 camera. What is the correct path that I am suppose to use?
My second question is this.
On my S3 I don't have to really ask for any permissions other than in the manifest so I'm trying to understand how this whole permission thing works. In the Manifest I have.
<uses-feature
android:name="android.hardware.camera2"
android:required="true" />
But in some of the example I am looking to learn permissions I see.
<uses-permission android:name="android.permission.CAMERA" />
Am I suppose to use both of these? I had learned Camera is outdated and Camera2 is what is used. Should that be android.permission.CAMERA2?
My camera doesn't work on my Pixel 3 but the code does work on my S3. So I need to learn how to code this differently apparently.
Google doesn't really give great examples on any of this. And the web is simply flooded with a lot of the wrong way to do things aka old ways.
If anyone can explain to me the changes on how this works on API 28 so I can learn how to add the slow motion camera etc or point me to an example that isn't out dated and made for android api 28 your help would be appreciated.

Related

What is Android 11's equivalent of '/dev/null'

Android 11 introduced multiple changes to file storage and access. Apparently one of them is that one can no longer target output to '/dev/null' (my scenario is actually exactly explained in this old question).
Although the cited question solved the particular issue, one thing remains unanswered: what is Android 11's equivalent to '/dev/null'. That is, if one does not need the output of a particular operation (and in our case it is an operation that creates a biggish file).
Eventually I ended up solving my problem the following way (answer tailored to MediaRecorder problem but can be generalized to other situations too):
fun MediaRecorder.setOutputFile(context: Context) {
val tmpRecordingFolder = File(context.filesDir, "tmp_media")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setOutputFile(File(tmpRecordingFolder, "recording.mp3"))
} else {
setOutputFile("/dev/null")
}
}
Basically I am setting the output to be in the internal storage. I hope the file will not get huge and I am deleting the file in as many places in the code as possible. This seems to work on newer devices, currently have not yet ran into storage problems either, but the solution is not rolled out to production yet. Will update my answer if problems are identified.
I had the same issue, you'll have to specify a path since MediaRecorder crashes in Android 11 if you don't provide it, in order to avoid writing a massive file you could try to flush the file by stopping / restarting MediaRecorder, I been dealing with this issue for a few days too.
I replied a more detailed answer here: MediaRecorder Android 11 start failed -1004

Is it possible to use stbi_load on Android?

I am a newbie on openGLES, I just want to open an image serve my texture later.
Since most tutorial on the internet for openGL is based on development on laptop, they simply open image like:unsigned char *data = stbi_load("pic.jpg", &width, &height, &nrChannels, 0); and put the picture under same folder. But I then realized for Android set a correct path is not that simple. If I put the picture under same folder with my cpp file, it will not be found during runtime since the app is now on the real phone.
So the question is, Is it possible to use stbi_load on Android? Or should I find another way? BTW I have to use JNI and write opengl logic with CPP.
I figure it out by myself in case someone encounter same issue.. Note in android you need to read from Sdcard not from drawable. Remember to grant permission.

I want to store the contents of a .dat file located on an external memory device (sd or usb) into a String?

I apologize in advance if this question or a similar question has already been resolved, but from my search on this site and others, I have failed to resolve my problem.
As the question title suggest, I wish to store the contents of a *dat file located on an external usb or sd card into a String variable within my main activity for further processing. I am new to java and android app development and only started tinkering a few days ago (I am an embedded design/robotics engineer and only have experience writing firmware in c/c++ for microcontrollers).
Could anyone suggest a way to do this, provide a code example, or provide a link to documentation or a library (or class) that I could use that would simplify things for me? I've been wrestling with this for several hours experimenting with various code snippets from the web. Please explain your response if you can, I am a newbie when it comes to java, app development, and android.
Also, do I need to edit the manifest to permit reading of files? If so, how?
Thanks in advance,
Caleb

MediaMetadataRetriever mostly stopped working since update to Ice Cream Sandwich

Since I upgraded my Galaxy S2 to Android 4 I am having some weird problem with my audio player application.
Since the upgrade MediaMetadataRetriever doesn't output much info other than the track number and the embedded picture. No title, no artist, pretty much nothing.
I am currently at a loss, as the problem is just made worse that the Android 4.0.3 emulator doesn't have the same problem.
Googling for this didn't help much, although I find it hard to imagine that I would be the only one with this kind of problem. My wife's SGS2 shows the same problem, so I don't expect it to be some strange problem limited to my phone.
Does anybody know if that might be a problem limited to ICS for the SGS2?
Did anybody else experience problems with MediaMetadataRetriever on ICS?
And, I guess most importantly, does anybody have a solution for this?
In case you want to check if my application has that problem on your phone you can get either code or APKs at http://www.sourceforge.net/projects/andrstoryteller
Any general advice on how I might be able to track down the problem would help as well.
I will test your sample application when I have a moment but in the meantime you may also want to think about another solution besides MediaMetadataRetriever since it limits your API compatibility and (apparently) doesn't always work. My project, ServeStream, uses a stripped down version of Apache Tika to retrieve the metadata. You may want to consider this approach in your own project. Here is a URL to the Tika jar and the class to do the parsing:
http://servestream.svn.sourceforge.net/viewvc/servestream/trunk/lib/tika-app-1.0.jar?view=log
http://servestream.svn.sourceforge.net/viewvc/servestream/trunk/src/net/sourceforge/servestream/utils/MetadataRetriever.java?revision=1033&view=markup
I noticed the same issue on ICS (On Galaxy SII and Galaxy Tab II both running ICS 4.0.3).
This seems to impact only mp3.
I guess one of the solutions as William suggested would be to use an external library but I also prefer to use what android offers rather then external libraries.
What bothers me is that I cannot find other posts reporting the same issue apart from this one. Though, I don't think I am doing it wrong:
I have tried two solutions:
MediaMetadataRetriever mmdr = new MediaMetadataRetriever();
mmdr.setDataSource(path);
String title = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
and
File file = new File(path);
FileInputStream inputStream;
inputStream = new FileInputStream(file);
mmdr = new MediaMetadataRetriever();
mmdr.setDataSource(inputStream.getFD());
inputStream.close();
String title = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
MediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE) always retuns null.
The path is correct and the mp3 file does have the ID3 tag with the title and everything.
A solution that I thought of apart from using an external library would be to query the MediaStore on the file's path:
Cursor c = mContext.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.MediaColumns.TITLE},
MediaStore.MediaColumns.DATA + "=?",
new String[] { path }, null);
String title;
if(c!=null && c.moveToFirst())
title = c.getString(c.getColumnIndex(MediaStore.MediaColumns.TITLE))
}
If the MediaScanner scanned it (it should have), the info should be there. This should also work for API levels before 10.
Basically, what I do in my project is the following: If SDK version is < 10 or the file's extension is mp3 and SDK version is 15, I query the MediaStore, otherwise I use MediaMetaDataRetriever.
A little update on the situation.
I have just put a couple of Ogg/Vorbis files onto my phone and there it can read the tags properly.
Will have to test with some more files, but maybe this has only stopped working for MP3 files.
Would be cool if I could get a couple of more people with ICS phones to test this.
Anyway, I'm currently looking into an alternative way to get this information, so I probably won't be using MediaMetadataRetriever for much longer.

Why does accessing Android MediaStore, using MonoDroid, generate UnauthorizedAccessException?

When I attempt to use the solution presented on SO here for dealing with large bitmaps in Android, I get an UnauthorizedAccessException at the point I'm trying to read from the file system from a location such as:
/mnt/sdcard/DCIM/Camera/IMG_20111223_122513.jpg
Is there a particular permission in my manifest I was supposed to select, or something else going on?
Well, there is always this one:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If you're looking to display a screen-sized version of a full-resolution photograph, may I please refer you to the Android Training article on this subject.

Categories

Resources