How do i use java file class in my mono for android c# project ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I did File>Open>File.Java
Now in my project i have Activity1.cs there i did:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using Android.App;
<span style="color:Blue; using Android.Content;
<span style="color:Blue; using Android.Runtime;
<span style="color:Blue; using Android.Views;
<span style="color:Blue; using Android.Widget;
<span style="color:Blue; using Android.OS;
<span style="color:Blue; using Android.Speech.Tts;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using MonoAndroidApplication1;

<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Timers;
<span style="color:Blue; using System.Threading;
<span style="color:Blue; using Android.Media;



<span style="color:Blue; namespace SayItAndroid{ [Activity (Label = <span style="color:#A31515; "SayItAndroid", MainLauncher = <span style="color:Blue; true)]
<span style="color:Blue; public <span style="color:Blue; class Activity1 : Activity, TextToSpeech.IOnInitListener
{
<span style="color:Blue; int count = 1;
TextToSpeech mTts;
AudioRecord ar;
MediaRecorder recorder;

<span style="color:Blue; public <span style="color:Blue; void OnInit (<span style="color:Blue; int status)
{
Console.WriteLine (<span style="color:#A31515; "Listening to text to speech");
}
<span style="color:Blue; protected <span style="color:Blue; override <span style="color:Blue; void OnCreate (Bundle bundle)
{

<span style="color:Blue; base.OnCreate (bundle);<span style="color:Green; // Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
Intent checkIntent = <span style="color:Blue; new Intent();
checkIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData);
StartActivityForResult(checkIntent, 100); <span style="color:Green; // Get our button from the layout resource, // and attach an event to it
Button button = FindViewById<Button> (Resource.Id.MyButton);
button.Click += <span style="color:Blue; delegate
{


<span style="color:Blue; string myText1 = <span style="color:#A31515; "Did you sleep well?";
<span style="color:Blue; string myText2 = <span style="color:#A31515; "Hi";
mTts.SetSpeechRate((<span style="color:Blue; float)0.5);
mTts.Speak(myText1, QueueMode.Add, <span style="color:Blue; new Dictionary<<span style="color:Blue; string, <span style="color:Blue; string>());
mTts.Speak(myText2, QueueMode.Flush, <span style="color:Blue; new Dictionary<<span style="color:Blue; string, <span style="color:Blue; string>());
};
}
<span style="color:Blue; protected <span style="color:Blue; override <span style="color:Blue; void OnActivityResult (<span style="color:Blue; int requestCode, Result resultCode, Intent data)
{
<span style="color:Blue; base.OnActivityResult (requestCode, resultCode, data);
<span style="color:Blue; if(requestCode == 100)
{
mTts = <span style="color:Blue; new TextToSpeech(<span style="color:Blue; this, <span style="color:Blue; this);
}
}
}}
[/code]
<br/>
How do i call and use the java class in the Activity1.cs ?

<hr class="sig danieli

View the full article
 
Back
Top