every native android application is and always has been written in java numbnuts
Printable View
Javascript is easy, a lot of people are confused between java and javascript what they think it's the same but it's not true.
btw, maks would you mind to use node.js to solve your problem with udp?
anyway:
Code:var udp = require('udp-request')
var socket = udp()
socket.on('request', function (request, peer) {
console.log('request:', request.toString())
socket.response('echo: ' + request.toString(), peer)
})
socket.listen(10000, function () {
socket.request('hello', {port: 10000, host: '127.0.0.1'}, function (err, response) {
console.log('response', response.toString())
socket.destroy()
})
})
before to execute this, you need to do npm install, I don't know about UDP, what do you really except?
the code you posted is the thing I was successfully able to do in 3 different languages.
I want a background service that sends a broadcast *when I receive a phone call*. As far as I know I can only do that in java or xamerin.
The same thing you wrote, in VB
and in pythonCode:Sub Main()
'Console.WriteLine("Receiver")
Do
Dim UDPClient As UdpClient = New UdpClient()
UDPClient.Client.SetSocketOption(SocketOptionLevel.Socket, _
SocketOptionName.ReuseAddress, True)
UDPClient.Client.Bind(New IPEndPoint(IPAddress.Any, 44126))
Try
Dim iepRemoteEndPoint As IPEndPoint = New _
IPEndPoint(IPAddress.Any, 44126)
Dim strMessage As String = String.Empty
Do
Dim bytRecieved As Byte() = _
UDPClient.Receive(iepRemoteEndPoint)
strMessage = Encoding.ASCII.GetString(bytRecieved)
Console.WriteLine("This is the message you received: " + strMessage)
My.Computer.Audio.Play("C:\Users\overwatch\Downloads\mario coin.wav", AudioPlayMode.WaitToComplete)
Loop While (strMessage <> "exit")
UDPClient.Close()
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
Loop
and I had that part of it working in c# as well but I deleted it out of anger when I deleted my other 20 aborted projectsCode:import os
while 1:
from socket import *
s=socket(AF_INET, SOCK_DGRAM)
s.bind(('',44126))
m=s.recvfrom(1024)
print m[0]
#Uncomment for Mac version
os.system("afplay ./ring.wav")
#Uncomment for Windows
#os.system("start .\ring.wav")
No library needed to install UDP, except the audio "play" basically npm install playCode:var PORT = 44126;
var HOST = '127.1.1.1';
var client = dgram.createSocket('udp4');
var play = require('play');
client.on('listening', function () {
var address = client.address();
console.log('UDP Server listening on ' + address.address + ":" + address.port);
});
client.on('message', function (message, remote) {
console.log(remote.address + ':' + remote.port +' - ' + message);
play.sound('./sound-files/ring.wav');
});
//calling
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
if (err) throw err;
console.log('UDP message sent to ' + HOST +':'+ PORT);
});
I simulated it, it looks like it's working.
https://i.imgur.com/mdHKEZi.png
Left window is which it calls eg. sending a broadcast, basically a function which is related to client.send to what's address and some stuff.
Right window is *when I receive a phone call* it outputs a log with some address info, it can do whatever like playing sound.
that's great now I have the same thing I already wrote in 5 languages
onyx-viper sounds like a deviantart fursona
dude I can make applications that send packets back and forth all day long, that part is easy. I could do it with telnet and netcat without writing a single line of code. writing an android application that does it when you recieve a phone call is a pain in the balls.
java, that's 6 langaugesCode:
public void myRealMethod(View view) {
String messageStr = "Fuck java";
int server_port = 44126;
try {
DatagramSocket s = new DatagramSocket();
InetAddress local = InetAddress.getByName("192.168.255.255");
int msg_length = messageStr.length();
byte[] message = messageStr.getBytes();
DatagramPacket p = new DatagramPacket(message, msg_length, local, server_port);
s.send(p);
} catch (Exception e) {
}
I'm p sure that one works but I can't figure out how to fucking call a fucking method that doesn't fucking return anything
Why don't you make a client version for android? running a server in the mobile it's tedious, however you need to create a separate backend server.
elzzz are u still a virgin? plz don't become a furry, qt mestiza hookers are so cheap in your country
powershell, 7 languages
Code:$port=44123
$endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$port)
$udpclient=new-Object System.Net.Sockets.UdpClient $port
$content=$udpclient.Receive([ref]$endpoint)
[Text.Encoding]::ASCII.GetString($content)
write-host $content
The client version can do REST to backend server in real time which is background service that client is listening everytime, then call a sound file, the backend server is the alarm that sends udp packet to notify every devices when the phone rings.
That's another possible design.
if I can't figure out how to read the phone state I can't do a goddamn thing
You need to use this service https://www.twilio.com to get phone state, also it's used to make outbound calls
why do I need a voip api to use functionality that's built into android
this is what I need I just don't know enough about the structure of an android project to get the fucking thing working
https://developer.android.com/refere...eListener.html
fuck java
Yeah, API levels and Permissions belong the Android systems are pain in the ass, even Java is outdated and shitty syntax to read like @Override and class with inside of function.
However, NativeScript is fucking awesome, basically if you port Java shitty code to Javascript which is very easy to do UI.
https://www.nativescript.org
You showed me PhoneStateListener, I make an example as incoming call like this:
It's ugly code, however it can be ported to Javascript with Nativescript.Code:private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
}
}
tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
It looks nice, you can integrate any elements as UI including getting phone state and incoming number.Code:var callStateListener = android.telephony.PhoneStateListener.extend({
onCallStateChanged: function (state, incomingNumber) {
}
var application = require("application");
var tm = application.android.context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
tm.listen(new callStateListener(), android.telephony.PhoneStateListener.LISTEN_CALL_STATE);
frankly I'd too irritated with the whole thing to spend any more time on it, but I'll give that a shot I think it's more or less the same thing dp recommended
So good
Thanks g
Uys
I got it working, sort of. I successfully spawned a background service, it detects incoming calls and sends a packet like it should. however
on the emulator, I need to specify an address, a broadcast address won't work. probably because the emulator thinks it's on cellular and you can't broadcast on a wan
on the actual phone, it only works if the app is in the foreground, the service doesn't seem to be listening after I hit the home button.
What good is a background server going to do if the notifier application on the phone doesn't work
I need to figure out how services work in more depth