Unable to download file from firebase through android studio - firebase

i just want to download an image from Firebase storage,but i am having these issues.My google play service is up to date.I have an image "dog.jpg" in bucket and no other file.
Firebase bucket
My mainActivity code
public class MainActivity extends AppCompatActivity {
private StorageReference pathRef = FirebaseStorage.getInstance().getReference().child("dog.jpg");
private ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView) this.findViewById(R.id.imageView);
}
public void getImage(View v){
File localFile;
try {
localFile = File.createTempFile("images","jpg");
pathRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
#Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
//Local temp file has been created
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
//handle error
Toast.makeText(MainActivity.this, e.getMessage()+"\n"+e.getCause(), Toast.LENGTH_LONG).show();
}
});
}catch (IOException exception){
Toast.makeText(this, "IOEXCEPTION", Toast.LENGTH_SHORT).show();
}
}
}
Errors i am getting.
W/GooglePlayServicesUtil: Google Play services out of date. Requires 11020000 but found 9683470
W/DynamiteModule: Local module descriptor class for com.google.android.gms.firebasestorage not found.
I/DynamiteModule: Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:0
E/NetworkRqFactoryProxy: NetworkRequestFactoryProxy failed with a RemoteException:
com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0.
at com.google.android.gms.dynamite.DynamiteModule.zza(Unknown Source)
at com.google.android.gms.internal.ace.<init>(Unknown Source)
at com.google.android.gms.internal.ace.zzg(Unknown Source)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)
at com.google.firebase.storage.zzr.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/FileDownloadTask: Unable to create firebase storage network request.
android.os.RemoteException
at com.google.android.gms.internal.ace.<init>(Unknown Source)
at com.google.android.gms.internal.ace.zzg(Unknown Source)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)
at com.google.firebase.storage.zzr.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: null
android.os.RemoteException
at com.google.android.gms.internal.ace.<init>(Unknown Source)
at com.google.android.gms.internal.ace.zzg(Unknown Source)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)
at com.google.firebase.storage.zzr.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: null
android.os.RemoteException
at com.google.android.gms.internal.ace.<init>(Unknown Source)
at com.google.android.gms.internal.ace.zzg(Unknown Source)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)
at com.google.firebase.storage.zzr.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
whats wrong with my code...i even tried it on real device but still unable to download this file my storage rules are:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write:if true
}
}
}

Your Play services is not up to date as you suggest. This error message tells you what's going on:
W/GooglePlayServicesUtil: Google Play services out of date. Requires 11020000 but found 9683470
The message suggests that you're using client library version 11.0.2, but Play services 9.6.83 is installed on the device. The version of Play has to be greater than or equal to the version of the client library in order for things to work.

Related

e4 databinding converter exception not catch

I have created a custom converter to convert a String back into a Date.
public Object convert(Object fromObject){
if (fromObject != null && fromObject.toString().trim().length() == 0){
return null;
}
for (DateFormat f : formats){
try{
return f.parse(fromObject.toString());
}catch (ParseException e){
// Ignore
}
}
throw new RuntimeException(message);
}
Basically, if the string is not parsable a RuntimeException will be thrown.
I have added the converter to the update strategy in the data-dinding and it is being called.
The issue is when the exception is thrown. (For example when i start to type the date in the TextFiled). Instead of appearing the decorator field to indicated an error in the input, the exception is not catch.
The exception appears in the console log (The error in the logs is at the end of the question) as it seems that nobody is catching it.
What i am missing? The exception in the converter should be catch within the updateStrategy and display the error, shouldn't it?
!ENTRY org.eclipse.core.databinding 4 0 2017-08-18 15:16:27.816
!MESSAGE Invalid time Format
!STACK 0
java.lang.RuntimeException: Invalid time Format
at com.lsespace.earthcare.tds.gui.util.databinding.conversion.StringToJavaTimeTagConverter.convert(StringToJavaTimeTagConverter.java:21)
at org.eclipse.core.databinding.UpdateStrategy.convert(UpdateStrategy.java:715)
at org.eclipse.core.databinding.UpdateValueStrategy.convert(UpdateValueStrategy.java:1)
at org.eclipse.core.databinding.ValueBinding$3.run(ValueBinding.java:175)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:149)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:153)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:171)
at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:158)
at org.eclipse.core.databinding.ValueBinding.access$4(ValueBinding.java:147)
at org.eclipse.core.databinding.ValueBinding$1.handleValueChange(ValueBinding.java:46)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:70)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:117)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.fireValueChange(DecoratingObservableValue.java:61)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue$1.handleValueChange(DecoratingObservableValue.java:76)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:70)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:117)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.fireValueChange(AbstractObservableValue.java:82)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.notifyIfChanged(SimplePropertyObservableValue.java:126)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.access$3(SimplePropertyObservableValue.java:118)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue$1$1.run(SimplePropertyObservableValue.java:70)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:149)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:153)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:171)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue$1.handleEvent(SimplePropertyObservableValue.java:66)
at org.eclipse.core.databinding.property.NativePropertyListener.fireChange(NativePropertyListener.java:69)
at org.eclipse.jface.internal.databinding.swt.WidgetListener.handleEvent(WidgetListener.java:56)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1084)
at org.eclipse.swt.widgets.Text.wmCommandChild(Text.java:3117)
at org.eclipse.swt.widgets.Control.WM_COMMAND(Control.java:4939)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4794)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5115)
at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2446)
at org.eclipse.swt.widgets.Text.callWindowProc(Text.java:262)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4889)
at org.eclipse.swt.widgets.Text.windowProc(Text.java:2704)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5102)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2552)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3814)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
at org.eclipse.jface.window.Window.open(Window.java:794)
at com.lsespace.earthcare.tds.gui.jface.actions.EditConfigAction.run(EditConfigAction.java:39)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
at org.eclipse.jface.action.ActionContributionItem$$Lambda$57/765702264.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4228)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3816)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:161)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
This is the implementation of the UpdateStrategy that I use so exceptions in the converter are treated like validation exceptions.
/**
* This implementation of UpdateValueStrategy does not catch the exceptions thrown by the converter,
* thus letting the normal mechanism of ValueBinding deal with the exception as it will do with a
* validation exception.
*
*/
public class AlternativeUpdateValueStrategy extends UpdateValueStrategy {
public AlternativeUpdateValueStrategy() {
this(UpdateValueStrategy.POLICY_UPDATE);
}
public AlternativeUpdateValueStrategy(int updateStrategy) {
super(updateStrategy);
}
#Override
public Object convert(Object value) {
if (converter != null) {
return converter.convert(value);
}
return value;
}
}

Baidu map integration error in android 6 and above

I have implemented Baidu map in my application and it is working fine in android version below 6 but have problem with above android 6 versions.
I have implemented dynamic WRITE_SETTING permission for android 6. If user give permission to app then also Baidu MapView class not able to access it and it is crashing.
Error log as below
java.lang.SecurityException: Permission Denial: requires permission android.permission.WRITE_SETTINGS
at com.baidu.android.bbalbs.common.util.a.a(DeviceId.java:206)
at com.baidu.android.bbalbs.common.util.a.a(DeviceId.java:68)
at com.baidu.android.bbalbs.common.util.CommonParam.b(CommonParam.java:72)
at com.baidu.android.bbalbs.common.util.CommonParam.a(CommonParam.java:45)
at com.baidu.platform.comapi.c.c.p(Unknown Source)
at com.baidu.platform.comapi.c.c.c(Unknown Source)
at com.baidu.mapapi.a.b(Unknown Source)
at com.baidu.mapapi.map.MapView.a(Unknown Source)
at com.baidu.mapapi.map.MapView.<init>(Unknown Source)
Please help me to solve out this problem.
I had the same problem, due to different permission mechanism approach in Android 6 (as described in https://developer.android.com/training/permissions/index.html).
Solved asking write_settings permission in this way:
ActivityCompat.requestPermissions(this ,new String[]{Manifest.permission.WRITE_SETTINGS,1);
where "this" is an Activity containing method:
#Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] results) {
switch (requestCode) {
case 1: {
if (results.length > 0
&& results[0] == PackageManager.PERMISSION_GRANTED) {
//You had the permission
} else {
// Permission denied!
}
return;
}
// With additional 'case' you can handle additional permission check
}
}}

javafx error even though url is correct

Even though the path given is correct & image is displaying in scene builder, it is throwing error while running the application.
Executing C:\Users\433240\Documents\NetBeansProjects\UI\dist\run547088191\UI.jar using platform C:\Program Files (x86)\Java\jdk1.8.0_40\jre/bin/java
Device "Intel(R) G41 Express Chipset" (\\.\DISPLAY1) initialization failed :
WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302
null/Images/home.png
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1091)
... 23 more
Exception running application ui.Main
Java Result: 1
I had the same problem
Solution:
go to java controller class and write this code
private Image image;
#FXML
ImageView imageview; // type your imageview fixid
private void setImage(String url) {
try {
image = new Image(url);
imageview.setImage(image);
} catch (Exception e) {
System.out.println(e);
}
}

JavaFX Alerts not showing?

I don't have quite much information, but perhaps someone was facing the same problem. I wrote an application for some friends, and it includes some Alert Dialogues. The problem is that the alerts are not showing on one of the pcs it was tested (but on my pc, it does!). I have Windows 10 and Java 1.8.0_51, the testing system had Windows 7 and Java 1.8.0_60.
I styled it with css. This is how I implemented it (alarm is just an audioclip):
public void play(Stage stage, Callable<Void> func){
if (alert == null) {
alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Alarm");
alert.setHeaderText(LanguageLoader.getInstance().getLocalizedString("alarmDialog"));
alert.initOwner(stage);
alarm.setCycleCount(Timeline.INDEFINITE);
}
if (!alert.isShowing()) {
alarm.play();
stage.toFront();
stage.requestFocus();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
alarm.stop();
try {
func.call();
} catch (Exception e) {
e.printStackTrace();
}
}
}else{
alert.show();
}
}
Edit: I updated to 1.8.0_60 too, and the dialog isn't showing on my system either!
This is the exception I get:
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing
at javafx.scene.control.Dialog.showAndWait(Unknown Source)
at utils.Alarm.play(Alarm.java:38)
at note.NoteController.update(Controller.java:76)
at java.util.Observable.notifyObservers(Unknown Source)
at java.util.Observable.notifyObservers(Unknown Source)
at note.NoteModel.update(Model.java:57)
at java.util.Observable.notifyObservers(Unknown Source)
at java.util.Observable.notifyObservers(Unknown Source)
at utils.Watch.lambda$0(Clock.java:35)
at com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(Unknown Source)
at com.sun.scenario.animation.shared.TimelineClipCore.playTo(Unknown Source)
at javafx.animation.Timeline.impl_playTo(Unknown Source)
at javafx.animation.AnimationAccessorImpl.playTo(Unknown Source)
at com.sun.scenario.animation.shared.InfiniteClipEnvelope.timePulse(Unknown Source)
at javafx.animation.Animation.impl_timePulse(Unknown Source)
at javafx.animation.Animation$1.lambda$timePulse$26(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at javafx.animation.Animation$1.timePulse(Unknown Source)
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(Unknown Source)
at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$405(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
I use a timeline in the class Clock.. I guess that's the problem. can I build a working clock without using timeline?
It seemes like in Java 1.8.0_60, the showAndWait() method of the class Alert can't be called during an animation (basically that's what the exception says). The problem was that I used a timeline to check the system time, and showed an alarm when a certain time is reached. To solve the problem, I changed
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
alarm.stop();
try {
func.call();
} catch (Exception e) {
e.printStackTrace();
}
}
to this:
alert.showingProperty().addListener((observable,oldValue,newValue)->{
if (!newValue){
alarm.stop();
try {
func.call();
} catch (Exception e) {
e.printStackTrace();
}
}
});
So instead of waiting for some input, it simply listens to changes in the showing property. Don't know how to fix this if you use other alerts with more buttons though.

Internet data connection fails

My users are reporting that when they download a JSON file using WiFi, the app works like charm, but when they attempt to download the same file using their data connection: GPRS, 3G, 3.5G etc... the app force closes. It doesn't happen with all types of smartphones, e.g, with my LG Optimus Black it doesn't happen.
To retrieve this file I use an AsyncTask.
private class GetData extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... args) {
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet("http://url.com);
HttpResponse response = httpclient.execute(httpget);
strPlayers = inputStreamToString(response.getEntity().getContent()).toString();
}
catch (IOException e) { e.printStackTrace(); }
finally { httpclient.getConnectionManager().shutdown(); }
return null;
}
protected void onPostExecute(Void result) {
Players players = new Gson().fromJson(strPlayers, Players.class);
quantity_darkmatter.setText(String.valueOf(players.userName));
}
}
Here's the StackTrace()
java.lang.RuntimeException: Unable to start activity ComponentInfo{carl.fri.fer.omegan/carl.fri.fer.omegan.Research}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at carl.fri.fer.omegan.Research.onStart(Research.java:613)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3791)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1632)
... 11 more
What can be the problem?
For non-WIFI the connection might take considerably more time, so it might be an issue of connection timeout, when that happens strPlayers will be blank and as there is no errorhandling in onPostExecute this might give Gson.fromJson hickups and make it throw an exception... try testing that strPlayers!=null before trying to parse it or putting it in a try-catch block to see if it throws an exception of some sort.
Is there any output of the e.printStackTrace() in the doInBackground function?

Resources