Baidu map integration error in android 6 and above - baidu-map

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
}
}}

Related

Xamarin iOS NFC Session is invalidated unexpectedly

Have a Xamarin forms project and trying to hook in NFC reading to the app. Currently plumbing in the iOS native side of things. I've setup all the provisioning and options on the apple portal side of things and i've added the following to the entitlements:
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
</array>
</dict>
Also added to the info.plist:
<key>NFCReaderUsageDescription</key>
<string>NFC tag to read NDEF messages into the application</string>
The code i've got for my native dependency for iOS is as follows:
[assembly: Dependency(typeof(RFIDScannerHelper))]
namespace MyProject.Mobile.Platform.iOS
{
public class RFIDScannerHelper : IRFIDScannerHelper
{
public bool hasRFID()
{
return true;
}
NFCNdefReaderSession Session;
public void ScanRFID(Action<string> act, VisualElement el)
{
NFChecker nfchecker = new NFChecker();
Session = new NFCNdefReaderSession(nfchecker, null, false);
Session?.BeginSession();
}
}
public class NFChecker : NSObject, INFCNdefReaderSessionDelegate
{
public Action<string> nfcFoundAction;
public void DidDetect(NFCNdefReaderSession session, NFCNdefMessage[] messages)
{
foreach (NFCNdefMessage msg in messages)
{
if (msg.Records.Count() > 0)
{
nfcFoundAction.Invoke(new NSString(msg.Records[0].Payload, NSStringEncoding.UTF8));
}
}
}
public void DidInvalidate(NFCNdefReaderSession session, NSError error)
{
var readerError = (NFCReaderError)(long)error.Code;
if (readerError != NFCReaderError.ReaderSessionInvalidationErrorFirstNDEFTagRead &&
readerError != NFCReaderError.ReaderSessionInvalidationErrorUserCanceled)
{
}
}
}
}
When this runs it all seems to fire correctly but on start of session it goes straight to the DidInvalidate method in the ReaderDelegate and the error says "Session is invalidated unexpectedly".
Can anyone tell me what I could be missing out?
UPDATE
I've also tried the xamarin provided sample here. But I also receive the exact same error "Session is invalidated unexpectedly". I've mucked around with our provisioning but no combination changes this error. Has anyone even got the xamarin sample to work?
#matt, it's a Visual Studio 2019 error. You should select the Entitlements.plist in your project settings, but you are not able because the "entry" where you should insert the path is always disabled. I have reported the problem
https://developercommunity.visualstudio.com/content/problem/752711/xamarinios-i-cant-set-entitlements.html

Geolocation GetLastKnownLocationAsync() permission exception from Xamarin Forms - call fails and no permission prompt

GetLocationAsync fails on my Xamarin.Forms app.
I've got the latest Xamarin.Essentials nuget package.
I've set the necessary permissions in the info.plist.
I am calling this from my ViewModel.
The call is super simple:
var location = await Geolocation.GetLastKnownLocationAsync();
but it's both failing AND failing to prompt a user permission dialog even though my info.plist has been setup correctly with:
NSLocationWhenInUseUsageDescription
Insert reason
I'm asking and answering this question because it was a head scratcher, and I wasn't exactly sure what to be searching for or what the issue was.
My various searches pointed to many related issues but nothing that actually gets to the main problem.
The closest I got was actually this issue on the Essentials github page:
https://github.com/xamarin/Essentials/issues/634
This answer is inspired by Xamarin/Azure evangelist, Brandon Minnick --> take a look at his project where he handles a similar situation with the following code:
So what can we take away from the above? If you look at the context, he has connected his Views with his ViewModels in MVVM style. However, various libraries require that certain methods be called from the Main thread. This is the essence of the issue, and this is what this code can solve.
So to adopt the above code for the geolocation issue addressed in the question, I did the following:
Task<Xamarin.Essentials.Location> GetLocationFromPhone()
{
var locationTaskCompletionSource = new TaskCompletionSource<Xamarin.Essentials.Location>();
Device.BeginInvokeOnMainThread(async () =>
{
locationTaskCompletionSource.SetResult(await Geolocation.GetLastKnownLocationAsync());
});
return locationTaskCompletionSource.Task;
}
I'm using the above from my ViewModel from within a Task. Something like the following.
async Task ExecuteGetGeoLocationCommand()
{
try
{
var locationFromPhone = await GetLocationFromPhone().ConfigureAwait(false);
if (locationFromPhone is null)
return;
_location = locationFromPhone;
if (_location != null)
{
Console.WriteLine($"Latitude: {_location.Latitude}, Longitude {_location.Longitude}, Altitude: {_location.Altitude}");
}
else
{
Console.WriteLine($"Exiting geolocation");
}
catch (FeatureNotSupportedException fnsEx)
{
}
catch (Exception ex)
{
}
}
}
I hope it's helpful to someone else!
If you're using Xamarin.Essentials and aren't being prompted for permission on Android, make sure you've added all the necessary code to the Android Main Activity.
See https://learn.microsoft.com/en-us/xamarin/essentials/get-started?tabs=windows%2Candroid for details.
From the docs:
protected override void OnCreate(Bundle savedInstanceState) {
//...
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState); // add this line to your code, it may also be called: bundle
//...
and
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Unable to download file from firebase through android studio

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.

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);
}
}

Problems with javaFX building path MVC fxml

I am currently working on an administrator build in java FX 2.1 using netbeans 7.2
I have the following issues:
I am developing this particular tool in an MVC pattern, so I've created 3 packages called Model, view and Controller.
My problem is that when building the project in netbeans it would only read the files supposed to be in the view package if they're outside of it. Let me give you a context path:
.../administradorInfinix/view/
.../administradorInfinix/controller/
.../administradorInfinix/model
so it would only read the fxml files regarding the view if they are outside the view package (.../administradorInfinix/)
This is where I set the address of the file:
private void irInicioSesion() {
try {
replaceSceneContent("InicioSesion.fxml");
} catch (Exception ex) {
Logger.getLogger(AdministradorINFINIX.class.getName()).log(Level.SEVERE, null, ex);
}
}
You can see the file name is InicioSesion.fxml, which should be inside the view package but it won't load if this is the case.
This is the replaceSceneContent I'm using to search for the fxml files:
private Parent replaceSceneContent(String fxml) throws Exception {
Parent page = (Parent) FXMLLoader.load(AdministradorINFINIX.class.getResource(fxml), null, new JavaFXBuilderFactory());
Scene scene = stage.getScene();
if (scene == null) {
scene = new Scene(page,548,416);
//scene.getStylesheets().add(AdministradorINFINIX.class.getResource("demo.css").toExternalForm());
stage.setScene(scene);
} else {
stage.getScene().setRoot(page);
}
stage.sizeToScene();
return page;
}
And this is the error it gives me when trying to run (it builds just fine but it won't run)
> administradorinfinix.AdministradorINFINIX irInicioSesion
Grave: null
java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at administradorinfinix.AdministradorINFINIX.replaceSceneContent(AdministradorINFINIX.java:126)
at administradorinfinix.AdministradorINFINIX.irInicioSesion(AdministradorINFINIX.java:110)
at administradorinfinix.AdministradorINFINIX.start(AdministradorINFINIX.java:46)
at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
where line 110 is
replaceSceneContent("InicioSesion.fxml");
and line 126 is
Parent page = (Parent) FXMLLoader.load(AdministradorINFINIX.class.getResource(fxml), null, new JavaFXBuilderFactory());
I hope you can help me fix this problem.
You need to call the method FXMLLoader#setLocation with the URL of the FXML file. Have a look at the following source for an example of how to load FXML files:
https://github.com/cathive/fx-guice/blob/master/src/main/java/com/cathive/fx/guice/GuiceFXMLLoader.java
The FXMLLoader fails to locate the .fxml-file.
The problem is that your call to Class.getResource() returns null.
The exception thrown by FXMLLoader.load(null) is quite misleading, it should rather be something such as an ArgumentNullException.
You can fix the problem with loading your resource file by specifying the full package path, in my case a call like this works:
FXMLLoader loader = new FXMLLoader(new Employee().getClass().getResource("/de/mycompany/mypackage/view/loginform.fxml"));
I hope this helps.

Resources