How to send print log from flutter app? - debugging

How to get print console log and screen capture so that I can send stack trace to server?

You can get a screenshot of the FlutterView using native code.
On Android: Bitmap screenshot = flutterView.getBitmap();
On iOS, see this example from Apple.
See the platform channels documentation on mixing Dart and native code.
As for the stack trace, here are some tips from the Flutter Sentry library documentation.
To get a stack trace from within Flutter, override the onError handler:
FlutterError.onError = (FlutterErrorDetails details) async {
throw details;
};
To create a Zone with an error handler that catches all Dart exceptions, wrap your call to runApp in runZoned:
runZoned<Future<Null>>(() async {
runApp(new MyApp());
}, onError: (error, stackTrace) async {
if (error is FlutterErrorDetails) {
// use error.exception and error.stack
} else {
// use error and stackTrace
}
});

you can use f_logs package, this has a functionality on export logs to a directory on the phone, it has .db and .txt for the logs, and then you can use flutter_archive package to zip the file, and then use flutter_email_sender to send the zip file that contains the logs your development team. It worked for us, hope this will helps.

Related

NativeScript Firebase already initialized

I am using Firebase in my app and I've noticed when I am actively making changes and LiveSync updates the app it will sometimes say "firebase.init error: Firebase already initialized". This happens when the changes don't trigger a whole application restart (ex. an html file). It completely messes up my current authentication state and forces me to restart the app anyways.
Is there some way I can catch for this happening or prevent it? I can try to make a demo app for it, but I feel this might have happened to somebody already.
I am just using the standard firebase.init as shown in the documentation in my app.component, nothing special or different.
Instead of using on ngOnit of App.component, try to initlize firebase on app launch event.
applicationOn(launchEvent, (args: LaunchEventData) => {
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
});

How do I deal with a possible exception in a Xamarin Forms application deployed to iOS or Android?

I have a finished application which I would like to make available to run on the iOS and Android platforms.  I have tested the application as much as possible and it works without problem.  But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}

Xamarin BluetoothLE Plugin not working

I created a new Xamarin.Forms app to test basic Bluetooth functionality. I downloaded this plugin into both the Android project and the shared project:
https://github.com/aritchie/bluetoothle
I wrote this function in the shared project and am calling it from the OnCreate of my launch activity in my Android project:
public static async Task BroadcastBluetooth()
{
// (I do not await this function when I call it)
try
{
await Task.Delay(5000); // just to make sure we give enough time for all initialization to complete
_server = CrossBleAdapter.Current.CreateGattServer();
// exception thrown on this line
await _server.Start(new AdvertisementData
{
LocalName = "TestServer",
ServiceUuids = new List<Guid>()
});
}
catch (Exception e)
{
}
}
It throws this exception:
{System.NullReferenceException: Object reference not set to an
instance of an object. at
Plugin.BluetoothLE.Server.GattServer.StartAdvertising
(Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00095] in
C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:135
at Plugin.BluetoothLE.Server.GattServer.Start
(Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00011] in
C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:70
at App2.App+d__7.MoveNext () [0x00097] in
C:\Projects\app2\App2\App2\App.xaml.cs:49 }
I'm only doing something really basic so I must be missing something? The exception is referencing a directory path of the plugin's developer's machine (C:\dev\acr...) so either this plugin is broken or I'm doing something really wrong?
I am using the same plugin in a current project of mine and it is working fine. So I doubt the issue is within the plugin.
Some thoughts about what could cause the issue:
Are you testing this code on a real device that is capable of performing BLE Advertisement?
Do you have set the permissions accordingly in your android project?
Does BLE Advertising work when you use the native android apis?
It also would be helpful, if you could attach a repository with which I can reproduce the issue.

How to debug gmail-addons with real email

I want to create a gmail add-on. I've already created the quick start application:
https://developers.google.com/gmail/add-ons/guides/quickstart
So, trigger function for that example is :
function buildAddOn(e) {
// Activate temporary Gmail add-on scopes.
var accessToken = e.messageMetadata.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
var messageId = e.messageMetadata.messageId;
var senderData = extractSenderData(messageId);
var cards = [];
// Build a card for each recent thread from this email's sender.
if (senderData.recents.length > 0) {
senderData.recents.forEach(function(threadData) {
cards.push(buildRecentThreadCard(senderData.email, threadData));
});
} else {
// Present a blank card if there are no recent threads from
// this sender.
cards.push(CardService.newCardBuilder()
.setHeader(CardService.newCardHeader()
.setTitle('No recent threads from this sender')).build());
}
return cards;
}
In apps script editor, you can debug this function, but, since we are not in gmail, we can not get the "e" parameter, so actually you can not debug it with the real data.
I have deployed that example as a developer add-on and I can use it in my gmail account. I tried to find the function somewhere in the code, I put debugger; or console.log() but I was not able to debug in browser.
So, how can I debug gmail add-on script with real gmail data ?
Gmail addons can't run client-side code so the browser console will not be very helpful but we could use Logger to log messages to Script Editor or to use console to log messages to Stackdriver.
I'd suggest using the built in Logger: https://developers.google.com/apps-script/reference/base/logger.
You can view logs each time your add on runs.

Get youtube video's comments - dart

I'am trying to get youtube video's comments from my dart console application. I create application in google console.
Then I try to get video list:
import "package:googleapis/youtube/v3.dart" as youtube;
import "package:http/http.dart" as http;
void main() {
http.Client client = new http.Client();
youtube.YoutubeApi api = new youtube.YoutubeApi(client);
api.videos.list("title", id: "ZkGSR0Q492g").then((youtube.VideoListResponse list) {
// print("List length: " + list.items.length);
});
}
When I run this file in console - I get error:
Uncaught Error: DetailedApiRequestError(status: 403, message: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.)
I understand that I never indicated API-key applications. I think that the error due to this.
But I can not figure out where I need to specify it?
I guess you need to create an authenticated client using https://pub.dartlang.org/packages/google_oauth2_client (detailed instructions in the README.md)
Now I use package "googleapis_oauth". And in this package we have method clientViaApiKey in auth_io.dart. This is solve my problem.

Resources