Due to the problem mentioned here, I configure the mornitoring example code as follows, however my app can not detect the iBeacon advertiser deployed.
new a mornitoring Activity named MainActivity, except the onCreate method, all other code are the same as the sample code.
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "MornitoringActivity";
public static final String UUID = "UUID: D57092AC-DFAA-446C-8EF3-C81AA22815B5";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
TextView mInfoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInfoView = (TextView) findViewById(R.id.show_info_lable);
beaconManager.setDebug(true);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
Log.i(TAG, "on create complete!");
}
#Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
Log.i(TAG, "on destroy complete!");
}
#Override
public void onBeaconServiceConnect() {
beaconManager.setMonitorNotifier(new MonitorNotifier() {
#Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
mInfoView.setText("I just saw an beacon for the first time!");
}
#Override
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
mInfoView.setText("I no longer see an beacon");
}
#Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
mInfoView.setText("I have just switched from seeing/not seeing beacons: "+state); }
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", Identifier.parse(UUID), null, null));
} catch (RemoteException e) { }
}
}
copy class.jar in android-beacon-library/libs/ into myProject/libs/, and add it to build path
manually edit the AndroidManifest.xml, here is my xml file,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymornitoring"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:enabled="true"
android:exported="true"
android:isolatedProcess="false"
android:label="beacon"
android:name="org.altbeacon.beacon.service.BeaconService">
</service>
<service
android:enabled="true"
android:name="org.altbeacon.beacon.BeaconIntentProcessor">
</service>
<receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
</application>
Use Macbook running the BeaconOSX app to perform as an iBeacon advertiser.(And I've use the AirLocate app on iPhone 4s to confirm the iBeacon advertiser works, however fail to be detected by the iBeacon Locate android app developed by Radius Networks)
Then I ran myProject on Nexus 5, the logcat messages are as below
11-06 10:49:08.838: I/BeaconService(5023): beaconService version 2.0 is starting up
11-06 10:49:08.878: D/BeaconService(5023): No org.altbeacon.beacon.SimulatedScanData class exists.
11-06 10:49:08.878: I/BeaconService(5023): binding
11-06 10:49:08.908: I/BeaconService(5023): start monitoring received
11-06 10:49:08.908: D/BeaconService(5023): startMonitoring called
11-06 10:49:08.908: D/BeaconService(5023): Currently monitoring 1 regions.
11-06 10:49:08.928: D/BeaconService(5023): Waiting to stop scan for another 1100 milliseconds
11-06 10:49:08.928: D/BeaconService(5023): Scan started
11-06 10:49:09.938: D/BeaconService(5023): Waiting to stop scan for another 99 milliseconds
11-06 10:49:10.038: D/BeaconService(5023): Done with scan cycle
11-06 10:49:10.048: D/BeaconService(5023): Restarting scan. Unique beacons seen last cycle: 0 Total beacon advertisement packets seen: 0
This idicate the BeaconService works well.
11-06 10:48:41.238: D/BtGatt.GattService(1483): registerClient() - UUID=6eaaf541-90fb-4e88-a0d5-1f267769128b
11-06 10:48:41.248: D/BtGatt.GattService(1483): onClientRegistered() - UUID=6eaaf541-90fb-4e88-a0d5-1f267769128b, clientIf=5
11-06 10:48:41.248: D/BtGatt.GattService(1483): startScan() - queue=0
11-06 10:48:41.248: D/BtGatt.GattService(1483): startScan() - adding client=5
11-06 10:48:51.258: D/BtGatt.GattService(1483): stopScan() - queue=1
11-06 10:48:51.258: D/BtGatt.GattService(1483): stopScan() - queue empty; stopping scan
11-06 10:48:51.258: D/BtGatt.GattService(1483): unregisterClient() - clientIf=5
11-06 10:48:41.238: D/BluetoothAdapter(1365): startLeScan(): null
11-06 10:48:41.248: D/BluetoothAdapter(1365): onClientRegistered() - status=0 clientIf=5
11-06 10:48:51.258: D/BluetoothAdapter(1365): stopLeScan()
11-06 10:49:08.918: D/BluetoothAdapter(5023): startLeScan(): null
11-06 10:49:08.928: D/BluetoothAdapter(5023): onClientRegistered() - status=0 clientIf=5
11-06 10:49:10.038: D/BluetoothAdapter(5023): stopLeScan()
11-06 10:49:10.048: D/BluetoothAdapter(5023): startLeScan(): null
I notice that there are two apps on my Nexus 5, who print the same BluetoothAdapter log msgs. Does this matter? And the didEnterRegion/didExitRegion has never been called. What could the problem be?
Related
Does Xamarin support multiple levels of project reference nesting, where the referenced project includes Android components intended for the AndroidManifest.xml?
For example: AndoidXamarin App > ClassLibrary1 > (which declares a Service) ClassLibrary2 (which also declares a Service):
// ClassLibrary1:
// Referenced by the XamarinApp
// References ClassLibrary2
namespace ClassLibrary1
{
[Service(Exported = true, Name = "com.company.test." + nameof(ClassLib1Service))]
public class ClassLib1Service : Service
{
public override IBinder OnBind(Intent intent) => throw new NotImplementedException();
}
}
// ClassLibrary2
// Referenced only by ClassLibrary1
namespace ClassLibrary2
{
[Service(Exported = true, Name = "com.company.test." + nameof(ClassLib2Service))]
public class ClassLib2Service : Service
{
public override IBinder OnBind(Intent intent) => throw new NotImplementedException();
}
}
// The generated `AndroidManifest.xml` only includes the Service defined in ClassLibrary1.
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="#style/AppTheme" android:name="android.app.Application">
<activity android:label="#string/app_name" android:theme="#style/AppTheme" android:name="crc64a7a6b04b89628087.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:exported="true" android:name="com.company.test.ClassLib1Service" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.company.test.mono.MonoRuntimeProvider.__mono_init__" />
</application>
I am receiving this error when trying to launch a Xamarin forms application on Android from a text message URL. I have been following the steps noted in THIS article.
Here the application node in my AppManifest.xml
<application android:label="Label A">
<activity android:icon="#drawable/Icon" android:label="LabelB" android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="superduperapp" />
</intent-filter>
</activity>
</application>
According to the article I need to do something with intent objects to get the OnCreate override to fire but I think I am not matching something up right with my manifest and the naming convention for a class I created below.
[Activity(Label = "urlentryclass")]
public class OpenFromURI : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Intent outsideIntent = Intent;
var x = Intent.Data.EncodedAuthority;
}
}
So, with the above code added to my xamarin solution I also have a webpage with the code below..
and when i click the link above from my mobile browser it touches the mobile app because I get the error below
MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity" on path: DexPathList[[zip file "/data/app/MyApp.Mobile.Droid-1/base.apk"],nativeLibraryDirectories=[/data/app/MyApp.Mobile.Droid-1/lib/arm64, /data/app/MyApp.Mobile.Droid-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] occurred
MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity"
Xamarin.Android, by default, generates the Java wrappers using MD5-based class names to avoid Java class name clashing, such as:
md579731053346ff64fcf21847b09163ce1.MainActivity
You have hard-coded a android:name=".MainActivity" in your manifest but the generated class will be MD5-based by default.
Open up your MainActivity and within the ActivityAttribute on your MainActvity class, add a fully qualified name within a Name parameter of that attribute, this will force the Xamarin.Android build process to use a Java-class name of your choosing vs. the MD5-based one and thus it will match your manifest entry.
Example:
[Activity(Name = "MyApp.Mobile.Droid.MainActivity", Label = "MySuperDuperApp", MainLauncher = true, Icon = "#mipmap/icon")]
public class MainActivity : Activity
{
~~~
I created this small application. I build the application and can see the icon on the emulator when I clicked the icon, the page opens without showing anything and then it closes again without showing any error. I cancelled the build and then it shows the below message in the output window:
C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.0\zipalign.exe 4 "C:\VisualStudioMobileApplication\App3\App3\App3.Android\bin\Debug\com.companyname.app-Signed-Unaligned.apk" "bin\Debug\\com.companyname.app-Signed.apk"
1>Done building project "App3.Android.csproj" -- FAILED.
1>Build FAILED.
1>
1>Deploy failed on VisualStudio_android-23_arm_phone
1>Process was cancelled
Build has been canceled.
It does not give any error. I also put the break point on "OnCreate" method in MainActivity.cs file.The code does not break on that breakpoint even when I click on App3 icon.Below is my code for MainActivity.cs
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace App3.Droid
{
[Activity(Label = "App3", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Xamarin.FormsMaps.Init(this, bundle);
LoadApplication(new App());
}
}
}
The code on MainPage.xaml is below:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App3"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="App3.MainPage">
<StackLayout VerticalOptions="StartAndExpand" Padding="30">
<maps:Map WidthRequest="960" HeightRequest="700"
x:Name="MyMap"
IsShowingUser="True"
MapType="Street"
/>
</StackLayout>
</ContentPage>
The code in MainPage.xaml.cs is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace App3
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyMap.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(37, -122), Distance.FromMiles(1)));
}
}
}
I am using Visual studio 2017 enterprise version 15.6. The build of the entire project is always successful.
Below are my androidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.app" android:installLocation="auto">
<uses-sdk android:targetSdkVersion="27" />
<application android:label="app3.android">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyD1K1njDAN0"/>
</application>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
I really need help to display the map when I click on App3. Any help will be highly appreciated.
On Windows, if you're using Hyper-V for your emulator, you can try this:
Start Hyper V manager
Select your machine under 'Hyper-V Manager'
Under Virtual Machines, right click on the VS emulator you are
trying to run your app on, select Settings.
Expand the 'Processor' node, select Compatibility.
Check the 'Migrate to a physical
computer with a different processor version' box, click OK and try
running your app again.
Hope it helps. Cheers!
I have a singleton service on remote server, this has a method who returns new objects to clients:
public class MySingleton : MarshalByRefObject
{
public override object InitializeLifetimeService()
{
return null;
}
public MarshalByRefObject GetService()
{
return new Model();
}
}
public class Model : MarshalByRefObject
{
}
I don't want that Model instances live forever on server, so I just wanted to use the normal sponsorship procedure, on client side I create a sponsor for my Model, and I attach the remote lease to this sponsor:
var sponsor = new ClientSponsor();
_service = _mySingleton.GetService();
var success = sponsor.Register(_service);
Well, this does not work. The remote object Model, dies after a while.
Do you confirm this behavior ?
I guess it's because the lifetime manager on server doesn't have the opportunity to initialize the lease, because the object Model is instanced and returned directly.
I know this is an old post but during my search for an similar issue I stumbled on this post.
Maybe it will depend on the SinkProvider configuration. Because the Renewal call on Client side from server require an deserialization. In the app.exe.config on server side you have to setup the serverProvider and also the clientProvider like this:
<channel ref="tcp" port="50220" useIpAddress="false">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
<channel ref="http" port="50221" useIpAddress="false">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="soap" />
</clientProviders>
</channel>
On the client side use the following app.config.exe:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="0">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
I am working with REST (using WCF) from past 2 years but new to Entity Model & Linq, however have used nHibernate.
I made a simple service with folloiwng :-
NorthwindModel [A data model having Product, Order and Order_Detail tables]
ProductService exposed as REST with specific config (not using WebServiceHostFactory)
Service Contract :-
[ServiceContract]
public interface IProductService
{
[OperationContract]
[WebGet(
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)
]
IList<Product> GetProducts();
}
Service Implementation :-
public class ProductService : IProductService
{
#region IProductService Members
public IList<Product> GetProducts()
{
IList<Product> prodList = new List<Product>();
NorthwindEntities ne = new NorthwindEntities();
var query = from category in ne.Products select category;
prodList = query.ToList<Product>();
return prodList;
}
#endregion
}
Service Tag :-
<services>
<service name="HellooData.ProductService" behaviorConfiguration="wcfJSONBehavior">
<endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding"
contract="HellooData.IProductService" bindingConfiguration="RESTBINDING">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange" bindingConfiguration="RESTBINDING" />
</service>
</services>
Binding : -
<webHttpBinding>
<binding name="RESTBINDING" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
After trying to call the service from the browser i get "Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data" error in Chrome and an empty page in Mozilla.
Have tried to debug but data is fetched properly (77 records) and returned without any exception. I somehow have a doubt in config or size of the data but not sure. Did try
to tamper the result set (only 2 instead of 77) result was still the same.
Can someone indicate what's going wrong?
I had this exact issue; in my case, I was disposing the database context before my SQL controller finished using it.