NLog log file on Xamarin - Android issues - android

I have been trying to use NLog from android, and it works whilst using a console based output. However when i try to target an external storage area/file nothing happens....there is no log file created...
My manifest contains the following lines:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
My Nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target name="logfile" xsi:type="File" fileName="storage\emulated\0\Download\log.txt" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Error" writeTo="logfile" />
</rules>
</nlog>
My activity MainActivity.cs :
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Logger sm_logger = LogManager.GetCurrentClassLogger();
sm_logger.Debug("test output");
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
}
All of this code runs, no errors seem to be thrown, however no file is created either...using the console logger does infact output to the console however... Any help would be appreciated.
Note:
Im using both the emulator and a device, neither have a log file created.
Im building for android 7.1 level 25 of api.
The NLog.config file is bundled as a androidasset, and seems to load as it can find the targets etc

It is not enough to have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
you also need to request the persmission with something like
ActivityCompat.RequestPermissions(Adapter.Activity, new String[] { Manifest.Permission.WriteExternalStorage }, 1234);
(which is incomplete, you also need to handle the permission result, but there are good resources out there on how to do that).
This needs to happen before the NLog FileTarget is created.

Related

Child list of getStorageDirectory always return null on Android 11

I want get child list of /storage directory by targetSdk=30 app.
So, I settings android.permission.MANAGE_EXTERNAL_STORAGE permission to AndroidManifest.xml and I created this code.
(I don't plan to distribute this app, so there is no problem granting this permission.)
<manifest>
...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
...
</manifest>
Environment.getStorageDirectory().list() // return null
However, as comment in the code, this code will always return null...
Can you please help me?
(I'm not good at English, so going through a translation service. Sorry if it's not clear.)
Remove tools:ignore="ScopedStorage" this line from your code and check permission for scope storage.
You need to take full access of storage so need to take scoped storage for android 11 or upper devices.

Adding a Gps Layer to my android application using arcgis runtime sdk in android studio

I am trying to add a GPS layer to my map in my app.
the problem is that am not getting a good result from the code. Am getting a red highlights on some of the codes.
This is code below.
// create the tiled layer and add to map (could also be an ArcGISLocalTiledLayer)
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.getLayers().add(tiledLayer);
// create a GPS layer and add to map
GPSLayer gpsLayer = new GPSLayer();
map.getLayers().add(gpsLayer);
Use LocationDisplay instead of GPSLayer
// get the LocationDisplay from MapView
LocationDisplay mLocationDisplay = mMapView.getLocationDisplay();
mLocationDisplay.start();
Don't forget to add these lines in your manifest file:
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
Look at samples for more details:
https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/display-device-location

Launcher icon Xamarin Android not found

I'm doing a Hello World in Xamarin Android, but when I try to change the launcher icon, it throws the following error: "No resource found that matches the given name (at 'icon' with value '#drawable/icon')."
Actually I don't have any "icon" in my resources, the icons' names are ic_launcher:
And my manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="HelloWorldXamarinAndroid.HelloWorldXamarinAndroid" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="Hi android" android:icon="#drawable/ic_launcher"></application>
</manifest>
I've already cleaned the project and tried to rebuild it, can someone help me?
If I change all the images' names to "Icon.png" and the manifest with "#drawable/Icon", it works, my question is, why Xamarin doesn't work with other names
I found the problem, in Main Activity is set the icon too, so it's necessary to set the new name there too:
[Activity(Label = "HelloWorldXamarinAndroid", MainLauncher = true, Icon = "#drawable/ic_launcher")]
public class MainActivity : Activity
{
...
}
Right click the Droid project and select Android Manifest from the menu list. Under Application Icon you will see which icon the application is referencing.
Below is a picture of where the icon is being references.

Getting started with osmdroid, mapview shows only grid

I am planning to use OSM in my android app and i decided to give osmdroid a try. Here is what i have done till now.
1: I downloaded the slf4j-android-1.5.8.jar and osmdroid-android-3.0.8.jar and copied them to my libs folder and added them to build path.
2: My Xml layout file code looks like this.
<org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
3: I have added all the permissions to the manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4: My on create method looks like this
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mapify);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mapController = mapView.getController();
mapController.setZoom(15);
}
My problem is that despite the code running fine i am not able to see the map when i run on my emulator. I am connected to internet and am able to see maps while using google map view.
I have look around the internet and also some questions in stackoverflow regarding same issue. Most of them either seem to have forgotten to add permissions or to add slf4j to build path. I have done both so i am at loss at what have i done wrong. Would be very grateful if you provided some insight.
Solved:
I don't know what is the reason but the map displays after i relaunch it a few times. After that everything seems to work fine. This happens again when i try in new virtual device. When i close and relaunch the app few times it starts working fine.
This is an old question, but in case somebody needs the answer. This may be caused if the emulator does not have an external storage to cache map tiles. I created an emulator with SD card and that solved the problem
open street maps (osmdroid) shows grey tiles not map in PC

I get "nextRation is null!" error trying to use Adwhirl + AdMob in Android

I've been trying to solve this problem for weeks. There are some other similar questions in StackOverflow, and there are some (apparently solved) similar issues in AdWhirl documentation website (one and two), but this error is still bothering me.
AdWhirl documentation is rather incomplete and confusing. The steps I've followed:
I created an AdMob account and I got the AdMob ID.
I created an AdWhirl account, I put there the AdMob ID and I got the AdWhirl ID.
I added in my Java Build Path the AdMob SDK Jar 4.3.1 and the AdWhirl SDK Jar 3.1.1
In my Manifest file I added the following lines:
.
<manifest>
[...]
<application>
[...]
<activity android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data android:value="[AdWhirl ID]" android:name="ADWHIRL_KEY"/>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
In all the layouts I want ads I added the following lines:
.
<com.adwhirl.AdWhirlLayout
android:id="#+id/adwhirl_layout"
android:layout_width="fill_parent"
android:layout_height="72dip" />
In all the activities related to those layouts I added the following lines:
.
public class XXX extends ListActivity implements AdWhirlInterface {
[...]
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.YYY);
initAds();
[...]
}
[...]
private void initAds() {
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setTestMode(false);
AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);
adWhirlLayout.setAdWhirlInterface(this);
}
public void adWhirlGeneric() {
Log.e(AdWhirlUtil.ADWHIRL, "In adWhirlGeneric()");
}
}
Project Build Target: Google API Android 4.0
Emulator: Google APIs 2.1 (API 7)
What am I doing wrong?
I see no ads and all the time I get the "nextRation is null!" error.
This looks like pretty much like the minimalistic AdWhirl implementation. FYI, you don't need the adWhirlGeneric() method.
There are a couple of reasons nextRation may be null.
The AdWhirl servers may have been down during the time you had this issue, or that you misconfigured some settings in the AdWhirl UI. These errors are unlikely.
AdWhirl tried to request an AdMob ad, and it failed for whatever reason (my money is on lack of inventory), and AdWhirl had no next ration, meaning there are no more ad networks to try to request an ad from (and it will try again on next refresh).
NOTE: A Ration in AdWhirl represents an ad network settings, like network name and it's corresponding network id.
Check the logcat output again, and see what leads up to the nextRation is null error. Is it a JSONException? If so, that means you have issue #1. Do the logs say you found an AdMob ration, then AdMob responded with onFailedToReceiveAd, and then you get nextRation is null? Then you have issue #2.
I had the same issue and found a solution following this post:
http://code.google.com/p/adwhirl/issues/detail?id=27
Hope it can help you too.

Categories

Resources