I'm writing an app in Xamarin Android, that is supposed to print the LAN address of the device using the app.
Here is what I try:
using System;
using Android.OS;
using Android.App;
using Android.Views;
using Android.Widget;
using Android.Net.Wifi;
using Android.Content;
using Java.Util;
using Java.Net;
namespace checks
{
[Activity(Label = "checks", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
Button dataButton = FindViewById<Button>(Resource.Id.connectionDataButton);
dataButton.Click += (object sender, EventArgs e) =>
{
WifiManager wifiManager = (WifiManager)GetSystemService(Context.WifiService);
var d = wifiManager.DhcpInfo;
Console.WriteLine("My IP IS: {0}",d.IpAddress);
};
}
}
}
I keep getting: MY IP IS: 0
Can anybody tell me what's wrong?
You should check if any wifi network is available first, if not, DhcpInfo.ipAdress returns 0.
Related
the code is working perfectly but after publishing it just doesn't open.
I created a page to test graphics, however as the webbrowser C# does not work, as it starts in IE I tried to use Cefsharp but it is not going either,the error that appears to me is Cefsharp.Core.Runtime.dll, the version I am using of cefsharp is 94.4.11. but the problem is that when I use it by Visual Studio 2022 it works but when I do the compilation and I publish it to generate the executable it doesn't just give an error or it doesn't even open
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cefteste
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
criarcef(panel1,p);
}
ChromiumWebBrowser p;
private void Form1_Load(object sender, EventArgs e)
{
}
private void criarcef(Panel panel, ChromiumWebBrowser chromium)
{
/*CefSettings settings = new CefSettings();
settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/GPMDP";
settings.WindowlessRenderingEnabled = true;
settings.CefCommandLineArgs.Add("enable-smooth-scrolling", "1");
settings.CefCommandLineArgs.Add("enable-overlay-scrollbar", "1");
settings.CefCommandLineArgs.Add("enable-npapi", "1");
CefSharp.Cef.Initialize(settings);*/
chromium = new ChromiumWebBrowser("C:/Users/Bill/Downloads/index(1).html");
chromium.LoadingStateChanged += (sender, args) => {
if (args.IsLoading == false)
chromium.ExecuteScriptAsync("document.oncontextmenu = function() { return false; };");
};
panel.Controls.Add(chromium);
chromium.Dock = DockStyle.Fill;
}
}
}
I create a program for adding sales posts to the Facebook marketplace. I have a problem with adding a photo because it shows me an error like in the title. I am surprised but when I tried to add a picture in google graphics the same way (IWebElement and variable) it worked very well. I don't want to use the api.
Does anyone know how to solve it?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using System.Threading;
namespace MARKETPLACE_v2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string url = "https://www.facebook.com/";
ChromeDriver driver; Thread th;
private void Form1_Load(object sender, EventArgs e)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-notifications"); // to disable notification
driver = new ChromeDriver(options);
driver.Navigate().GoToUrl(url);
}
private void button1_Click(object sender, EventArgs e)
{
driver.FindElement(By.XPath("//button[normalize-space()='Akceptuj wszystkie']")).Click();
driver.FindElement(By.XPath("//input[#id='email']")).SendKeys("login");
driver.FindElement(By.XPath("//input[#id='pass']")).SendKeys("password");
driver.FindElement(By.XPath("//button[contains(text(),'Zaloguj się')]")).Click();
//login
driver.FindElement(By.XPath("//*[name()='path' and contains(#d,'M17.5 23.7')]")).Click(); Thread.Sleep(2000);
driver.FindElement(By.XPath("//div[#class='j83agx80 cbu4d94t d6urw2fd dp1hu0rb l9j0dhe7 du4w35lb']//span[#class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v lrazzd5p knomaqxo']//span[1]")).Click(); Thread.Sleep(3000);
driver.FindElement(By.XPath("//span[contains(text(),'Przedmiot na sprzedaż')]")).Click(); Thread.Sleep(3000);
IWebElement element = driver.FindElement(By.XPath("//div[#class='s45kfl79 emlxlaya bkmhp75w spb7xbtv bp9cbjyn rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv pq6dq46d taijpn5t l9j0dhe7 tdjehn4e qypqp5cg q676j6op']//i[#class='hu5pjgll lzf7d6o1']"));
element.SendKeys(#"C:\download\maciek.jpg");
}
}
}
I'm trying to code a Skype Tool in C# with the SKYPE4COMLib. It is showing me the messages in Skype, but they keep loading all the time. Any ideas how to fix that?
My Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SKYPE4COMLib;
namespace SkypeTool
{
public partial class mainmenu : Form
{
Skype skype = new Skype();
public mainmenu()
{
InitializeComponent();
}
private void connect_Click(object sender, EventArgs e)
{
skype.Attach(5, false);
status.Text = "connected";
}
private void button1_Click_1(object sender, EventArgs e)
{
skype.SendMessage("censored", "Test");
}
}
}
This is happening for almost everyone. I think it's because of the skype update. There is a way to "Fix It" you can use open message dialog in skype4com. It will look like this.
Skype.Client.OpenMessageDialog(name goes here, message goes here);
Skype.Client.Focus();
Sendkeys.Send("Key that u want to use to send message")
You Can Also See this here How To: Fix Skype4Com SendMessage Problem!
The speech is working fine on my real device.
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;
namespace App7
{
[Activity(Label = "App7", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity, TextToSpeech.IOnInitListener
{
public TextToSpeech SpeechText
{
get;
set;
}
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// create text to speech object to use synthesize and speak functions.
// first parameter: context
// second parameter: object implemeting TextToSpeech.IOnInitListener
this.SpeechText = new TextToSpeech(this, this);
Button testButton = FindViewById<Button>(Resource.Id.button1);
testButton.Click += delegate
{
this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);
};
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
public void OnInit(OperationResult status)
{
// here you can setup language settings
if (status.Equals(OperationResult.Success))
Toast.MakeText(this, "Text To Speech Succeed!", ToastLength.Long).Show();
else
Toast.MakeText(this, "Text To Speech Fail", ToastLength.Long).Show();
}
}
}
The warning is on this line:
this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);
Under this line there is a green line and the warning message is:
Warning 1 'Android.Speech.Tts.TextToSpeech.Speak(string, Android.Speech.Tts.QueueMode, System.Collections.Generic.IDictionary)' is obsolete: 'deprecated'
Tried to google didn't find anything.
I can ignore it but I would like to know what does it mean ? And how can I fix it ?
It means this overload is deprecated in Xamarin (because Google marked it as deprecated as of API level 21).
Use the other two overloads (1, 2) that aren't deprecated if the warning bothers you and your target API level allows it, or just ignore the warning.
I have this code:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;
using System.Collections.Generic;
namespace SayItAndroid{ [Activity (Label = "SayItAndroid", MainLauncher = true)]
public class Activity1 : Activity, TextToSpeech.IOnInitListener
{
int count = 1;
TextToSpeech mTts;
public void OnInit (int status)
{
Console.WriteLine ("Listening to text to speech");
}
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
Intent checkIntent = new Intent();
checkIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData);
StartActivityForResult(checkIntent, 100); // Get our button from the layout resource, // and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate
{
string myText1 = "Did you sleep well?";
string myText2 = "I hope so, because it's time to wake up.";
mTts.Speak(myText1, QueueMode.Add, new Dictionary<string, string>());
mTts.Speak(myText2, QueueMode.Flush, new Dictionary<string, string>());
};
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
if(requestCode == 100)
{
mTts = new TextToSpeech(this, this);
}
}
}}
But on the two places i have Resource im getting red line error under the Resource:
Error 1 The name 'Resource' does not exist in the current context
How can i solve it ?
Thanks.
The reason that Resource cannot be found is 9 out of 10 times because the Resource is not in the same namespace as the file you are referring it from.
As stated on this page by Xamarin, the project's default namespace is used to store the generated Resource class file in.
If your class resides in another namespace things break.
Hope that clears things up for you.