CameraX Saving images to file, FileNotFoundException: (Permission Denied) - java

I'm working with Android Studio, writing in Java. I'm trying to write a piece of software that will take pictures from a camera based on an event. So first steps first was to figure out the API. Camera is depreciated, so there's Camera2, but the latest is CameraX. I've attempted to use both CameraX and Camera2, but for some reason I'm not saving any images. I believe the capture works, but the issue is saving the files. I don't know what's going on.
First lets start with permissions. Yes, I have set permissions for both the camera and external storage.
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
So lets move on to the code itself.
I've never saved photos before, but I have worked with text files such as .txt and .csv files. Which I've been able to make work.
Right now I do a simple button click to capture the image. Which is nothing more than an onclicklistener. Once I press the button this is what actions occur.
SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
File file = new File(Environment.getDataDirectory(), mDateFormat.format(new Date())+ ".jpg");
if(!file.exists())
file.mkdirs();
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(file).build();
imageCapture.takePicture(outputFileOptions, executor, new ImageCapture.OnImageSavedCallback () {
#Override
public void onImageSaved(#NonNull ImageCapture.OutputFileResults outputFileResults) {
Toast.makeText(MainActivity.this, "TEST", Toast.LENGTH_SHORT).show();
new Handler().post(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, "Image Saved successfully", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onError(#NonNull ImageCaptureException error) {
error.printStackTrace();
// Toast.makeText(MainActivity.this, "Image save FAILED!!!!", Toast.LENGTH_SHORT).show();
}
});
when the app launches the first time, it asks for permission and I grant permission. but looking at the run tab as part of the Android Studio ID, I get the following readout, when I press the capture button
D/ImageCapture: Send image capture request [current, pending] = [0, 1]
D/CaptureSession: Issuing capture request.
W/example.camera: JNI critical lock held for 21.148ms on Thread[14,tid=10076,Runnable,Thread*=0xdc743000,peer=0x13184cf8,"Binder:10045_2"]
W/ExifInterface: Stop reading file since a wrong offset may cause an infinite loop: 0
Skip the tag entry since data format (ULONG) is unexpected for tag: GPSAltitudeRef
W/ExifInterface: Stop reading file since a wrong offset may cause an infinite loop: 0
Stop reading file since a wrong offset may cause an infinite loop: 0
W/System.err: androidx.camera.core.ImageCaptureException: Failed to write or close the file
W/System.err: at androidx.camera.core.ImageCapture$3.onError(ImageCapture.java:669)
at androidx.camera.core.ImageSaver.lambda$postError$1$ImageSaver(ImageSaver.java:263)
at androidx.camera.core.-$$Lambda$ImageSaver$eAp-cZyzsEk-LVLazzLE-ezQzwo.run(Unknown Source:8)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.io.FileNotFoundException: /data/20200728142756.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at androidx.camera.core.ImageSaver.run(ImageSaver.java:97)
... 3 more
W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 6 more
W/example.camera: JNI critical lock held for 17.651ms on Thread[16,tid=10083,Runnable,Thread*=0xdc74bc00,peer=0x13184de8,"Binder:10045_4"]
I've searched around, and looked for different methods of saving the file, and I've had success with saving the image, sort of, when I use the camera2 api and save the file using outputstream
When I use Camera2 it appears to save just fine, but I have no idea where it saves, I can't find it. I point this out, because it still appears to be a permission denied error as what I'm seeing is when I open up Device File Explorer its not letting me view /storage/emulator/ it just shows me
ls: /storage/emulated/: Permission denied.
all the examples I have found have assumed access with no issues to emulated.
Does anyone have any insight as to why I'm having permission denied errors?
UPDATE
So I still haven't solved the issue related to the failed mkdir() call. However, I did fix one issue, that could have been causing the issue. The means as to how I was creating the directory and the file itself wasn't correct.
SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
File file = new File(getBatchDirectoryName(), mDateFormat.format(new Date())+ ".jpg");
public String getBatchDirectoryName() {
String app_folder_path = "";
app_folder_path = Environment.getExternalStorageDirectory() + "/images";
File dir = new File(app_folder_path);
if (!dir.exists() && !dir.mkdirs()) {
Toast.makeText(MainActivity.this, "Trip", Toast.LENGTH_SHORT).show();
}
return app_folder_path;
}
However, it still fails to create the directory. Which still makes me come back to a permission issue.
Environment.getExternalStorageDirectory() appears to be deprecated. Documentation appears to recommend using getExternalFilesDir(string) or MediaStore. However, I'm having issues finding sample use cases. And I can't imagine, that while deprecated, it would just stop working at all. Most devices on the market are not API 29 or higher.

Based on help from #blackapps, I was able to make changes to my Manifest file to allow access to external storage.
More information can be found here
Request Legacy External Storage
With #blackapps, and this thread on stackoverflow I was able to update my permissions to allow legacy access.
Because in Android Q they have disabled direct file access, they have added a work around to allow legacy support. This is, and as others have mentioned, only a temporary fix for the issue. You will need to follow the new format for saving files going forward with Android R. In my situation, I am only developing a proof of concept and will not need to worry about future versions of Android.
To make the temporary fix, do the following
Add the following line
android:requestLegacyExternalStorage="true">
inside your <application bracket on the manifest file. Should look similar to this
<?xml version="1.0" encoding="utf-8"?>
...
package="com.example.camerax">
...
<application
...
android:requestLegacyExternalStorage="true">
<activity android:name=".MainActivity">
<intent-filter>
...
</intent-filter>
</activity>
</application>
remember this is not a long term fix, and will not work when a device is updated to Android R

Related

Android TransactionTooLargeException when calling TakePicture

Need to utilise the camera in my app for work, I see that things have changed in API >= 28 compared to how I used to do it where I could use startActivityForResult.
However I am facing a problem where I launch the camera app, and immediately get the 'TransactionTooLargeException' error message in the debug/run console.
For calling up the camera, I am doing
mGetContent = registerForActivityResult(
new ActivityResultContracts.TakePicture(),
result -> {
if (result) {
}
}
);
Where mGetContent is defined in the class as
private ActivityResultLauncher<Uri> mGetContent;
In my AndroidManifest.xml file I have the following
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
In my file_paths file I have
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="."/>
<files-path
name="app_images"
path="./files/"/>
</paths>
I have a button set up in my activity where I launch the camera using
findViewById(R.id.button)).setOnClickListener(v -> {
File directory = new File(context.getFilesDir(), "app_images");
if (!directory.exists()) directory.mkdir();
File file = new File(directory, "image.jpg");
Uri uri = getUriForFile(this, "com.test.fileprovider", file);
mGetContent.launch(uri);
};
As soon as I tap on the button, and the camera app opens up, I get what I can only assume is an overly general error message.
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1284092)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test, PID: 14296
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:511)
at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4524)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
Been trying to Google search to find things, but having trouble nailing down what the actual issue is.
Some suggestions pointed me towards the onSaveInstanceState, so I override that and set a breakpoint on it to see what was happening, but it made it through without any issues (from what I could tell).
Kind of at a loss with this one.
Wowsers as to what makes up the bundle in the onSaveInstanceState.
I have some imageviews, imagebuttons, and just general buttons in my app to make things easier for our staff.
I went through and changed the 'saveState' of all the ImageViews and ImageButtons from the default of true to false, since I don't care what state they were in, they are just visual guides.
Took the android:viewHierarchyState from 1.2MB down to 1.6KB, my Parcel size is now 3.3KB and it no longer crashes when suspending the app to bring up the camera app.
TooLargeTool was useful, but I couldn't make it work the way the Github page says, I told it to 'startLogging', and in my activity where the crash was happening, I set a breakpoint and checked if it was logging using 'isLogging' and it came back 'true'.
In the end I just had it log the output of TooLargeTool.bundleBreakdown(outState) in the onSaveInstanceState.
Thanks to Gabe Sechan and ianhanniballake for pointing me towards what it might be, there's not much out there on for this particular exception, I mean, there is, but it appears that it is different for everyone.
Really wish Google would print out a better set of error messages for it to make it easier to work out which activity was the problem (or in my case, all 3 activities combined).

permission denied for writing in the path returned by getFilesDir()

I need to create an audio file with synthesizeToFile.
It works on Android 6 (with the overloaded version of synthesizeToFile) but in Android 4.1 synthesizeToFile returns -1.
The synthesizeToFile official documentation says:
Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns.
Then, to know which error caused that -1 I searched in the logcat where I founded this exception:
E/TextToSpeechService: Can't use /data/data/com.domain.my/files/_12345_test.wav due to exception java.io.IOException: open failed: EACCES (Permission denied)
There is some different system configuration/setting between Android 6 and 4.1 which cause this error?
I must pass to synthesizeToFile a different path than the one returned by getFilesDir()?
I must set file permissions?
Code I used for Android 4.1:
TextToSpeech tts = new TextToSpeech(getApplicationContext(), this, "com.google.android.tts");
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
String textToGenerate = "this is a test";
// /data/data/com.domain.my/files is returned by getFilesDir()
String completePathFile = "/data/data/com.domain.my/files/_12345_test.wav";
File fileToGenerate = new File(completePathFile);
String fileName = fileToGenerate.getName();
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, fileName);
int response = tts.synthesizeToFile
(
textToGenerate
, hashMap
, completePathFile
);
Log.d("testTTS", "Generation file " + fileName + " - response = " + response);
}
}
I already checked with getEngines() that "com.google.android.tts" is installed.
I need to save the file in the internal storage so I must not ask for external storage permission (it is true also for Android 4.1? Or for this versione I need to do so?).
If I deliberately pass to synthesizeToFile a path that doesn't exists, the error in the logcat changes to file not found exception so that method checks correctly that the path completePathFile exists.
I came across your issue searching for a solution to my issue.
Use of sound files in TTS on Marshmallow (Android 6) fails with permission issues
For me, it's addspeech() in TTS.
I think permission issues on TTS come from the fact that TTS in a device is a separate application and the TTS app doesn't have permissions to write or read files in the external or internal storage of your app.
It's funny that I call the instance of TTS in my app code and use all its functions but they can't access my app's storage. TTS is not my app, so there's no way I can request permissions on behalf of TTS. I think it's a kind of bug Google has to handle.
Anyway, I let the Google team know the issue in the link below. They didn't respond yet though.
https://issuetracker.google.com/issues/152671139
You can support me in the link above, or you can post your own issue to let them know that there're multiple developers hoping TTS permission issues are taken care of.

Nearby Connections: Why is the payload file from the Downloads folder null?

I'm following the File transfer example on the Nearby Connections Exchange page (the "more complex example" code snippet).
I can send an image and receive it on another device in the Download/Nearby folder. The image is sent successfully since if I were to change the file name to give it an appropriate extension (e.g. .jpg), I can open the image in a photo gallery app.
private void processFilePayload(long payloadId) {
Payload filePayload = completedFilePayloads.get(payloadId);
String filename = filePayloadFilenames.get(payloadId);
if (filePayload != null && filename != null) {
completedFilePayloads.remove(payloadId);
filePayloadFilenames.remove(payloadId);
// Retrieve received file from Downloads folder
Payload.File payloadFile2 = filePayload.asFile();
File payloadJavaFile = payloadFile2.asJavaFile();
if (payloadJavaFile == null) {
Log.d(TAG, "Payload java file is null in processFilePayload()");
} else {
payloadJavaFile.renameTo(new File(payloadJavaFile.getParentFile(), filename));
}
}
}
Why is the payloadJavaFile variable null? From looking at Payload.class, I know that the result of asJavaFile() is a nullable File and that, from the asJavaFile() method description, calling asJavaFile() in processFilePayload() from within onPayloadReceived() (as is done in the example on the API page) may lead to the File not having received all of the payload's contents yet. However, I also call processFilePayload() from within onPayloadTransferUpdate() after verifying the success of the PayloadTransferUpdate, and so shouldn't the payload have received all of its contents by this stage (and not be null when calling asJavaFile() on the payload object)?
My code is almost the same as the documentation for both sending and receiving the image and file name.
Payload.asJavaFile() will be null if the READ_EXTERNAL_STORAGE permission is not properly set up for your application. You need READ_EXTERNAL_STORAGE in the AndroidManifest.xml and you need to also request READ_EXTERNAL_STORAGE permission at runtime since it is a dangerous permission. (https://developer.android.com/training/permissions/requesting)
To share files using Nearby Connections, your application will need all of the following:
AndroidManifest.xml
<!-- Required for Nearby Connections -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Optional: needed to share files -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
MainActivity.java
ActivityCompat.requestPermissions(thisActivity,
new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE
},
PERMISSIONS_REQUEST_CODE);
We will improve the documentation to make this requirement for sharing files more obvious.
I checked the source code. From what I can see, asJavaFile() is always set (and I'm not sure why it's marked as #Nullable).
Unfortunately, for me to look into it any further, I'd need you to provide me with a sample app that reproduces the bug you're seeing.

Streaming live video from Raspberry Pi to my Android App but getting security exception

I would like to stream live video to my android app.
I am using the motion service to stream live video from my raspberry pi's camera (small usb connected camera). I have it setup for port 8082 so I can successfully type in (exampled IP) "http://74.220.185.125:8082" from any browser and see my video streaming. However, when I use this in my code for my app using the videoView I get an Exception thrown each time.
MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Starting video
piVideo = (VideoView) findViewById(R.id.piVidView);
try{
piVideo.setVideoURI(Uri.parse("http://74.220.185.125:8082/"));
} catch (Exception e){
Log.e("Error found here->", e.getMessage());
e.printStackTrace();
}
piVideo.requestFocus();
piVideo.start();
piVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
piVideo.start();
}
});
}
Each time, I get this same error:
03-08 12:46:49.258 1412-1412/com.me.blah.app D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://74.220.185.125:8082/
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1141)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:991)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:914)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1121)
at android.widget.VideoView.openVideo(VideoView.java:371)
at android.widget.VideoView.access$2100(VideoView.java:71)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:652)
at android.view.SurfaceView.updateWindow(SurfaceView.java:712)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:209)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1014)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
I have INTERNET enabled in my manifest file:
"uses-permission android:name="android.permission.INTERNET"
I have tried rstp:// and http:// and both still end up with the same exception being thrown. Can anyone see where I this exception could being caused from?
So I actually found this simple solution about a week or so ago after searching & asking for roughly two weeks, and I noticed there were many other people asking the same questions or looking for a simple answer and I wanted to share what worked for me.
My search lead me to using a videoView, but from my understanding the videoView is searching for a specific file and/or a specific streaming file type that would normally be created on your remote server. However the motion service did not readily provide the file nor the details I was looking for, but the ip address definitely worked in a normal browser so I tried a webView instead, adjusted my pixel ratio on my raspberry pi in the motion.conf file, and played with the dimensions of my webView and it worked perfectly fine. The code was a lot easier than the examples I kept seeing and this is what I used:
String piAddr = "http://10.0.0.116:8081/"
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.loadUrl(piAddr);
NOTE: I am running a python script that starts the motion service on my raspberry pi and it seems that the timing between the app requesting the raspberry pi motion service port and the motion service actually starting up is slightly off, so throughout my code I just repeat the following line periodically to verify my video is streaming successfully.
Additionally, the webView has a scroll bar automatically so if you cannot see the entire video (with the timer at the bottom) you can always tweak your video dimensions on the pi in the motion.conf file.

Android Place Picker shows blank screen when place is selected, or when trying to return

I'm trying to implement in my android app the Google Maps Places API.
When a button is clicked it opens the place picker, the picker works fine (you can move around, zoom in and out, search and go to current location), until when you try to click on the "Select this location" button; when the button is clicked a blank screen opens, and the only option is to close the app.
The same happens when the back button is pressed (either the one the navigation bar, or the one in the AppBar)
Image: Inside the Place Picker Activity
Image: Blank Screen
It was working fine a few weeks ago, then it stopped working, one day ago it started working again, and today it stopped working.
Code to open Place Picker:
private void openPlacePicker() {
Log.i(TAG, "open place picker");
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
}
catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
And yes I've added a permission check for ACCESS_FINE_LOCATION, before executing the function.
Code for on Activity Result:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG, "onActivityResult");
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
final Place place = PlacePicker.getPlace(this, data);
(...)
My logs don't show any errors, and the OnActivityResult Logs aren't called:
D/libgps: proxy_gps_stop: called.
D/libgps: proxy_gps_status_cb: called.
D/libgps: proxy_gps_status_cb: called.
I/art: Background partial concurrent mark sweep GC freed 58725(4MB) AllocSpace objects, 23(2MB) LOS objects, 40% free, 14MB/23MB, paused 1.422ms total 101.850ms
D/gpsd: WakeLock(Release,GPSD)
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/GCoreUlr: Successfully inserted 1 locations
I/WifiHAL: Got channel list with 11 channels
I/WifiHAL: Got channel list with 9 channels
I/WifiHAL: Got channel list with 13 channels
W/ActivityManager: Launch timeout has expired, giving up wake lock!
My Manifest Meta Data and Permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
(...)
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIza(...)" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I've check in the Google Console Page, the package name and the SHA-1 fingerprint are correct.
When I'm at Overview > Google Maps APIs > Google Places API for Android > Usage, it shows no usage what so ever, when it should be showing some, because as I said previously, one day ago it was working and I used it.
This issue has happen on my Nexus 9 (Android N), and on the Moto G3 (Android M).
Note: On the Moto G it would work the first time, user would click a button, place picker opens, user clicks on picker's "Select Location" button, goes to previous activity everything works fine; but if he clicks on the button to open the picker again, and he tries to click on picker's "Select Location" button again, he would go to the blank screen, and would have to close the app and try again).
TLDR;
The Place Picker in my android app goes to a blank screen when I try to select a location or leave the Place Picker Activity.
Thanks
As noted by my earlier comment, I had the exact same problem earlier today.
What solved it for me was replacing:
compile 'com.google.android.gms:play-services:9.0.0'
with
compile 'com.google.android.gms:play-services-location:9.0.0'
This change was suggested from this Stack post
Note: If you're using more than just the location from the play-services library, make sure to include the other components like
compile "com.google.android.gms:play-services-games:9.0.0"
compile "com.google.android.gms:play-services-plus:9.0.0"
compile "com.google.android.gms:play-services-ads:9.0.0"
This error timeout has expired, giving up wake lock! means your Activity is taking to long to start. If you are doing a lot of processing on the UI thread, Android kills your application. You should use AsyncTask for any processing intensive stuff. Activity cannot be displayed because it is still trying to complete execution; meanwhile the ActivityManager has timed out.
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
Sample implementation of Asyntask:
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Long result) {
}
}
For blank screen when selecting locations, make sure you have the permission in your manifest file.
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/ >
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Categories

Resources