I can't connect to my Parse Dashboard from my Android Studio app - parse-platform

I've been trying to solve this issue of the I/o failure with my app. I put the android:usesCleartextTraffic="true" but even though it stills failing and I don't know what should I do now. This is my AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parseserver01">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".App"
android:usesCleartextTraffic="true"
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/Theme.ParseServer01">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is the App.java file.
package com.example.parseserver01;
import com.parse.Parse;
import android.app.Application;
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("HSBN")
// if defined
.clientKey(null)
.server("http://localhost:1337/parse/")
.build()
);
}
}
And the MainActivity.java file of my android app.
package com.example.parseserver01;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.List;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseObject parseObject = new ParseObject("TodoList");
parseObject.put("todo", "todo");
parseObject.saveInBackground();
ParseQuery<ParseObject> query = ParseQuery.getQuery("TodoList");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
System.out.println("-------------------------IT WORKS!!!!-------------------");
String dato = parseObject.getString("todo");
System.out.println(dato);
System.out.println("------------------------------------------------------------");
} else {
System.out.println("-------------------------FAILURE-----------------------------");
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(e.getCause());
System.out.println("------------------------------------------------------------");
}
}
});
}
}
And finally, this is the configuration of my Parse server (I'm using the parse-server-example because I'm just testing).
const config = {
databaseURI: databaseUri || 'mongodb+srv://hsbn:123#cluster0.omrau.mongodb.net/ParseData',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'HSBN',
masterKey: process.env.MASTER_KEY || 'kqsPdEFbul', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
},
};
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
"apps": [
{
"serverURL": "http://localhost:1337/parse",
"appId": "HSBN",
"masterKey": "kqsPdEFbul",
"appName": "Android Test"
}
]
});
I've also tried the /test of parse server and it completes all the 3 tests. Also I'm running the android app in my cellphone. Please help me.

Related

Xamarin Forms how to share page and open app from my current app with parameters? [duplicate]

Im trying to launch an app that I've created from another app that Im working on right now. The thing is I've been searching throught the internet and found something but it did not work so Im seeking help in here.
This is what I've done on the app I want to launch from :
On my xaml.cs :
public async void GoToDigDitApp(object sender, EventArgs e)
{
var appname = "digdit://";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appname);
}
I created an Interface:
public interface IAppHandler
{
Task<bool> LaunchApp(string uri);
}
In the Android project:
[assembly: Dependency(typeof(OpenAppAndroid))]
namespace SupervisingApp.Droid
{
[Activity(Label = "OpenAppAndroid")]
public class OpenAppAndroid : Activity, IAppHandler
{
public Task<bool> LaunchApp(string uri)
{
bool result = false;
try
{
var aUri = Android.Net.Uri.Parse(uri.ToString());
var intent = new Intent(Intent.ActionView, aUri);
Android.App.Application.Context.StartActivity(intent);
result = true;
}
catch (ActivityNotFoundException)
{
result = false;
}
return Task.FromResult(result);
}
}
}
And This is the app I want to launch manifest :
<?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.Tab2" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:label="Dig Dit" android:icon="#drawable/ic_launcher">
<activity android:icon="#drawable/ic_launcher" android:label="Dig Dit" android:name="digdit.urlentryclass">
<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="digdit" />
</intent-filter>
</activity>
</application>
</manifest>
For now Im only intressted by the Android part and it doesn't seem to work. I hope you guys can help me out.
You could use PackageManager.GetLaunchIntentForPackage.
Try the code below. com.companyname.app2 is the package name of App2.
Intent intent = PackageManager.GetLaunchIntentForPackage("com.companyname.app2");
StartActivity(intent);
Updated:
Create a interface:
public interface IDpendencyService
{
Task<bool> Launch(string stringUri);
}
Implemention of Android:
public class DependencyImplementation : Activity, IDpendencyService
{
public Task<bool> Launch(string stringUri)
{
Intent intent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(stringUri);
if (intent != null)
{
intent.AddFlags(ActivityFlags.NewTask);
Forms.Context.StartActivity(intent);
return Task.FromResult(true);
}
else
{
return Task.FromResult(true);
}
}
}
Usage of MainPage:
<StackLayout>
<!-- Place new controls here -->
<Label
FontAttributes="Bold"
FontSize="Large"
HorizontalOptions="Center"
Text="Welcome to App1!"
VerticalOptions="CenterAndExpand" />
<Button x:Name="GotoApp2" Text="GotoApp2" Clicked="GotoApp2_Clicked"></Button>
</StackLayout>
private void GotoApp2_Clicked(object sender, EventArgs e)
{
DependencyService.Get<IDpendencyService>().Launch("com.companyname.app2");
}
I have upload on GitHub, you could download from the StartAnotherApp_Xamarin.forms/App1 folder for reference.
https://github.com/WendyZang/Test.git
You can open you app from xamarin.forms
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Device.OpenUri(new Uri("digdit://555-1111"));
});

How to log every web api request in Insights with .NET 4.6.1

I have a .NET Framework 4.6.1 solution which has this global.asax.cs:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{ Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = EnvironmentHelper.InstrumentationKey;
HttpConfiguration config = GlobalConfiguration.Configuration;
GlobalConfiguration.Configure(WebApiConfig.Register);
}
protected void Application_Error(Object sender, EventArgs e)
{
_telemetry.TrackException(Server.GetLastError());
}
}
This WebApiConfig.cs:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Services.Add(typeof(IExceptionLogger), new InsightsExceptionLogger());
}
}
This logger class:
public class InsightsExceptionLogger : ExceptionLogger
{
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null)
{
var ai = new TelemetryClient();
ai.TrackException(context.Exception);
}
base.Log(context);
}
}
And this is an example of a controller and method:
public class SomeController : ApiController
{
[HttpPost, Route("api/v1/Something")]
public async Task<IHttpActionResult> Something()
{
The problem is I'm not getting any requests logged in Insights at all.
What do I need to do to get these API calls logged in Insights? (Assuming that simply adding .TrackRequest() is not necessary.)
Create a Request Telemetry initializer class and add the below code. On request Telemetry property you can select which property u want to add in a application insights.
After the Request Telemetry initializer class created add
<Add Type="webapptostoreloginappinsights.ReqTelemetryInitializer,webapptostoreloginappinsights"/>
in a applicationinsights.config file under telemetry processors
Make sure to call the request Telemetry initializer class in a global.asax.cs
Try to run the code now able to view the api request in a Application Insights
What I ended up doing was this....
Add packages:
<package id="Microsoft.ApplicationInsights" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Web" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.8" targetFramework="net472" />
Ensure web.config <system.web> contains this:
<httpModules>
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
During the process the ApplicationInsights.config file was created and once deployed the application started logging Reuqest entries in Insights.

xamarin-bluetooth-le does not scan devices

I am using xamarin-bluetooth-le to make BluetoothLE client side on Xamarin.
I searched few of BluetoothLE package (sample code is work fine).
Thus, I have choosed xamarin-bluetooth-le.
In fact, sample code work fine.
However, I am simplify sample code without view, becuse I am not need View and binding is not need.
However xamarin-bluetooth-le does not scan device by the simplify code.
First question:
In sample of xamarin-bluetooth-le, an event named DeviceDiscovered is need assign two times?(one is DeviceListViewModel constructor, the other is scan method).
Second(main) question:
Why xamarin-bluetooth-le does not scan device by below codes?
Environment is
Visual Studio 2019 16.10.0
Xamarin 16.10.000.228
Plugin.BLE 2.1.2
Other newest
Below is code:
BluetoothClient.cs
using Plugin.BLE;
using Plugin.BLE.Abstractions.Contracts;
using Plugin.BLE.Abstractions.EventArgs;
using Plugin.BLE.Abstractions.Extensions;
using System;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
namespace PlugInBLETest.NetowrkModels
{
public class BluetoothBLEClient
{
private IAdapter Adapter;
private IBluetoothLE Current;
public ObservableCollection<IDevice> DeviceList { get; }
private CancellationTokenSource CancelSource;
public BluetoothBLEClient()
{
Current = CrossBluetoothLE.Current;
Adapter = CrossBluetoothLE.Current.Adapter;
Adapter.DeviceDiscovered += OnDeviceDiscovered;
Adapter.ScanTimeoutElapsed += OnScanTimeoutElapsed;
Adapter.DeviceDisconnected += OnDeviceDisconnected;
Adapter.DeviceConnectionLost += OnDeviceConnectionLost;
DeviceList = new ObservableCollection<IDevice>();
}
public async Task SearchDevices()
{
if (Current.State == BluetoothState.Off)
{
return;
}
else
{
DeviceList.Clear();
foreach (var connectedDevice in Adapter.ConnectedDevices)
{
try
{
await connectedDevice.UpdateRssiAsync();
}
catch (Exception ex)
{
return;
}
}
CancelSource = new CancellationTokenSource();
Adapter.ScanMode = ScanMode.LowLatency;
Adapter.ScanTimeout = 30000;
//Adapter.DeviceDiscovered += (s, a) => DeviceList.Add(a.Device);
Adapter.DeviceDiscovered += (s, a) =>
{
DeviceList.Add(a.Device);
};
await Adapter.StartScanningForDevicesAsync(CancelSource.Token);
var temp = DeviceList.Count;
}
return;
}
private void OnDeviceConnectionLost(object sender, DeviceErrorEventArgs e)
{
}
private void OnDeviceDisconnected(object sender, DeviceEventArgs e)
{
}
private void OnScanTimeoutElapsed(object sender, EventArgs e)
{
}
private void OnDeviceDiscovered(object sender, DeviceEventArgs args)
{
}
}
}
AndroidManifext.xml
<?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.pluginbletest">
<uses-sdk android:targetSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application android:label="PlugInBLETest.Android" android:theme="#style/MainTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Xamarin.Essentials has a permissions feature that will allow you to check for and request permission for access to the location data
After Marshmallow you have to prompt for the user for permission -> https://devblogs.microsoft.com/xamarin/requesting-runtime-permissions-in-android-marshmallow/

DownloadRequest in volley plus not downloading file

I am trying to download a file using volley plus(https://github.com/DWorkS/VolleyPlus/blob/master/library/src/com/android/volley/request/DownloadRequest.java) . Here's my code:
#Override
public void downloadFile(String url, final String path, OnViewDocsFinished mListener) {
//url = "http://www.orimi.com/pdf-test.pdf"
//String name = "passport.pdf";
//String path = Environment.DIRECTORY_DOWNLOADS+"/"+name;
DownloadRequest request = new DownloadRequest(url, path,
createSuccessListener(mListener, path),
createErrorListener(mListener));
VolleySingleton.getRequestQueue().add(request);
}
private Response.Listener<String> createSuccessListener(final OnViewDocsFinished loginListener, final String path) {
return new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
Log.i(TAG, response.toString());
loginListener.onDownloadFinished(path);
} catch (Exception e) {
}
}
};
}
private Response.ErrorListener createErrorListener(final OnViewDocsFinished loginListener) {
return new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.toString());
}
};
}
The file is not getting downloaded to the location. Here's my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="in.yumigo.yumigovendor">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I am running my app on Android Lollipop. WHat's the issue here guys?
You trying to download file i.e.byte[] by making custom string request. If you make string request you will get only string response. In your case you need to make byte[] request.
Check below link how to setup custom request class for volley.
Implementing a Custom Volley Request.
This below link is making the same request what you are trying to make. Hope it may help you.
Downloading files using volley.

Xamarin Forms MainActivity OnCreate LoadApplication System.NullReferenceException: Object reference not set to an instance of an object

I am using VS2015 with Xamarin to create a multi-platform project that can show a splashscreen and then load a webpage in a webview. Here is my project structure. I am using a PCL project type as below:
TheApp (Portable)
-WebPageHoster.Xaml //Contains a WebView control
-WebPageHoster.Xaml.cs //sets the WebView controls source property to load a webpage
-App.Xaml
-App.Xaml.cs
TheApp.Droid
/Resources/drawable/splashlogo.png
/Resources/drawable/icon3.png
/Resources/values/Styles.xml
-MainActivity.cs
-SplashActivity.cs
TheApp.iOS
TheApp.WindowsPhone(Windows Phone 8.1)
This is the code in the Styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">#drawable/splashlogo</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
SplashActivity.cs
[Activity(MainLauncher = true, NoHistory = true, Theme = "#style/Theme.Splash", Icon = "#drawable/icon3")]
public class SplashActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var intent = new Intent(this, typeof(MainActivity));
StartActivity(intent);
Finish();
}
}
MainActivity.cs
[Activity(Label = "Splash App", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App()); // << Problem here
}
The LoadApplication method call in the OnCreate method above loads the app constructor of the App.Xaml.cs class which runs the following code
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new WebPageHoster() { Title = "Load Web-Page" });
}
This shows the splash screen and after setting the WebView's url reaches back to the OnCreate method and gives this error
System.NullReferenceException: Object reference not set to an instance of an object
I am unable to find what is causing this error. Here is the Android Manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="TheApp.TheApp" android:installLocation="auto" android:versionCode="1">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<application android:icon="#drawable/icon3" android:theme="#style/Theme.AppCompat" android:label="Splash Web Host"></application>
</manifest>
I tested your source code and your MainActivity derives from FormsAppCompatActivity.
In that case you must provide a theme that uses AppCompat.
To solve that, I added an AppCompat Theme to your styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
</style>
And then used it on your MainActivity:
[Activity(Label = "Southern Travel", Theme = "#style/AppTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

Resources