Successful Push Notifications from javapns but not showing up on ios devices - java

I'm using javapns 2.2 to send push notifications and am getting successful responses from it but the notifications are not showing up on my iOS test phone. I've created a unit test that uses this code from the wiki:
#Test
public void shouldSendATestMessageNotifyingDeviceThatNewMessageIsReady()
throws RepositoryException {
NotificationService nService = new NotificationService();
nService.sendNotification("incoming message",
"4854862ec7b58a939538f2e1262a48a7e8a3331c5f0e11feb11e1a79ff764649");
}
public void sendNotification(String message, String deviceId) {
try {
List<PushedNotification> notifications = Push.alert(message, certLocation, certPassword, false,
deviceId);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
/* Apple accepted the notification and should deliver it */
System.out.println("Push notification sent successfully to: " +
notification.getDevice().getToken());
/* Still need to query the Feedback Service regularly */
} else {
String invalidToken = notification.getDevice().getToken();
/* Add code here to remove invalidToken from your database */
/* Find out more about what the problem was */
Exception theProblem = notification.getException();
theProblem.printStackTrace();
/* If the problem was an error-response packet returned by Apple, get it */
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null) {
System.out.println(theErrorResponse.getMessage());
}
}
}
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I'm using the production push SSL cert (p12) that I created in keychain. I have an adhoc build on my iOS device and I pulled the device Id that I pass into this test from NSLog code in my iOS app for the device I'm using for testing so it is valid.
I swapped out my prod cert with the dev cert and got the invalid token error as I would expect to make sure it was finding the file.
Not sure what else to look at since javapns is telling me the pushed message was sent successfully. Ideas?

Related

Not able to connect to Aws Iot using AWSIotMqttManager and Aws Cognito credentials

I am using AWS Cognito for sign in and to get temporary credentials. I tried PubSub API in Ionic app in browser and it is working fine for Device shadow updates. Now I have written code in Java for android but the MqttManager keeps on reconnecting.
This a native code in Ionic 4 + Capacitor plugin
#PluginMethod()
public void Init(PluginCall call)
{
String clientId = call.getString("clientId", null);
if(clientId == null)
{
UUID uuid = UUID.randomUUID();
clientId = uuid.toString();
}
mqttManager = new AWSIotMqttManager
(
clientId,
"m6jklghidefabc-ats.iot.us-west-1.amazonaws.com"
);
String id = AWSMobileClient.getInstance().getIdentityId();
if(id == null)
{
call.reject("Could not get identity id");
return;
}
else
{
Log.i("Plugin===", id);
}
//
// Connect MQTT Manager
//
try
{
MqttPlugin th = this;
mqttManager.connect(AWSMobileClient.getInstance(), new AWSIotMqttClientStatusCallback()
{
#Override
public void onStatusChanged(final AWSIotMqttClientStatus status, final Throwable throwable)
{
Log.i("Plugin====", status.toString());
}
});
JSObject ret = new JSObject();
ret.put("clientId", clientId);
call.resolve(ret);
}
catch (final Exception e)
{
Log.i("Plugin==E=", e.getMessage());
call.reject(e.getMessage());
}
}
Status is Connecting then Reconnecting...
Reconnecting keeps getting printed in the Logcat
Please indicate me why this is failing to connect when the auth with AWS Cognito is working perfectly fine. My policies seems to be in place because from browser I am able to connect using PubSub api in Ionic 4 app

how to publish mqtt message with retained true in paho on android

I am using Paho java client library for my on android App. Code provided below.
MqttAndroidClient client_Panic = new MqttAndroidClient(this.getApplicationContext(), serverURL, CLIENT_ID);
try {
MqttConnectOptions options = new MqttConnectOptions();
options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1);
options.setCleanSession(false);
options.setKeepAliveInterval(90);
options.setConnectionTimeout(100);
IMqttToken token = client_Panic.connect(options);
//Few callbacks
} catch (MqttException e) {
e.printStackTrace();
}
And publishing messages, when required
String msg = "messages";
MqttMessage message = new MqttMessage();
message.setPayload(msg.getBytes());
try {
client_Panic.publish(topic, message);
} catch (MqttException e) {
e.printStackTrace();
}
It is working fine, but somehow incomplete. What I need is, whenever other client subscribed to same topic, should get the last retained message, which publisher might had published earlier.
For that I searched on their documentation, I got
protected void setWill(String topic,
MqttMessage msg,
int qos,
boolean retained)
So setWill as per documentation have the option to enable the retained option. So I tried with
options.setConnectionTimeout(100);
options.setWill(topic,null,2,true); // This place I added
IMqttToken token = client_Panic.connect(options);
But got error java.lang.IllegalArgumentException at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateWill on the line containing options.setWill.
Is setWill is the correct method for enabling retained true on android, if yes then what parameters need to be provided or else their is any other method for enabling it on android? TIA.
The Will is a very specific message that is only published if the client disconnects uncleanly from the broker (e.g. network drops).
You can not set a null message as the Will message which is what the error is about.
The retained state is specific to a given message so you do not set it globally, it is set on each message. To mark a message as retained when you just call the setRetained(boolean) e.g.
String msg = "messages";
MqttMessage message = new MqttMessage();
message.setRetained(true);
message.setPayload(msg.getBytes());
try {
client_Panic.publish(topic, message);
} catch (MqttException e) {
e.printStackTrace();
}

MIDI OUT transmitter not available

I've been banging my head on this all day, read everything I can find, followed the JDK source around, no luck in finding out the gory details about HOW or WHERE java looks to obtain data on a midi device and determines what's what.
I'm trying to capture midi messages through my NI Audio 8 DJ MIDI IN port, but, java isn't "seeing" the MIDI IN port, only the out, which I have successfully used to send midi with. I also get the same results with an M-Audio USB UNO midi device: MidiSystem.getMidiDeviceInfo() only "sees" the output port.
I have verified the operation of the MIDI IN port with:
amidi -p hw:2,0 -d
and sending it some signals. Works fine.
getMaxTransmitters() returns zero.
MidiSystem.getMidiDeviceInfo() shows only one entry for both devices: Audio8DJ [hw:2,0] or Interface [hw:2,0]
The code below works fine for a Receiver and I think is only the bits I need to verify that getTransmitter() grabs the port, since it just works for the other and everything works fine, up I get a MidiUnavailableException / Transmitter not available exception.
I've even taken the getMaxReceivers() trap out because I was just trying to see if the device only offered up the one entry and sorted it out, but no.
public static Transmitter getMidiIn () {
if (midiIn == null){
devices = MidiSystem.getMidiDeviceInfo();
for(MidiDevice.Info info: devices){
System.out.println("device class " + info.getClass());
MidiDevice device;
try{
device = MidiSystem.getMidiDevice(info);
if (info.toString().equals("Audio8DJ [hw:2,0]")){
if (device.getMaxTransmitters() != 0){
try{
device.open();
System.out.println("max transmitters:" + device.getMaxTransmitters());
midiIn = device.getTransmitter();
System.out.println("Found a transmitter: "+ midiIn);
break;
} catch (Exception e){
e.printStackTrace();
}
}
}
} catch (MidiUnavailableException e1){
e1.printStackTrace();
}
}
}
return midiIn;
}
So the thing that's getting me here is this: alsa lists only one entry in amidi -l and when I specify that as a port to dump, it works fine. Java gets that same text entry and can't sort out the MIDI IN, assigning it the com.sun.media.sound.MidiOutDeviceProvider class so it leaves me wondering just how does, or where does Java figure out what a device has to offer and why isn't it seeing the input port that alsa is seeing.
I'm coding with eclipse Version: 3.8.1 IDE with JDK1.6, on a linux mint OS, .
I'll be happy to provide anything asked for. Thanks for reading!
The solution to java seeing the transmitter was in the version of JDK being used, though unfortunately at this time, I do not have an answer as to why for the failure, just that one version worked and suits my needs for the time being. If I find that answer, I will edit this answer.
Of the three versions I was switching between for testing, jdk1.8.0_60, jdk1.7.0_80, jdk1.6.0_45, 1.7 did not experience the error and successfully obtained a transmitter from my device. I found this out, and that privileges were not the cause of my specific issue, by compiling and running some code I found suitable for command line execution that attempts to obtain the transmitter, prints out midi data sent to it, and modified it a little ...
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
public class MidiInputTest {
public MidiDevice input;
public MidiDevice output;
public static void main(String[] args) {
new MidiInputTest().start();
}
public void start() {
init(); // initialize your midi input device
// system dependent
try {
output.open(); // From midi device
MyReceiver myrcvr = new MyReceiver();
MidiSystem.getTransmitter().setReceiver(myrcvr);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private class MyReceiver implements Receiver {
Receiver rcvr;
public MyReceiver() {
try {
this.rcvr = MidiSystem.getReceiver();
} catch (MidiUnavailableException mue) {
mue.printStackTrace();
}
}
#Override
public void send(MidiMessage message, long timeStamp) {
byte[] b = message.getMessage();
if (b[0] != (byte)254) {
System.out.println((b[0] & 0xff) + " " + (b[1] & 0xff));
}
//rcvr.send(message, timeStamp); // will send out what ever you receive
}
#Override
public void close() {
rcvr.close();
}
}
public void init() {
MidiDevice.Info[] devices;
devices = MidiSystem.getMidiDeviceInfo();
try{
for (MidiDevice.Info info: devices) {
MidiDevice device;
device = MidiSystem.getMidiDevice(info);
System.out.println("MidiDevice.Info="+info + "\n" + "maxTransmitters="+device.getMaxTransmitters());
// I put the specific device I want to connect to behind an if gate here to avoid connecting to something I do not
if (info.toString().equals("Interface [hw:2,0,0]") && device.getMaxTransmitters() != 0) {
System.out.println(" Name: " + info.toString() +
", Decription: " +
info.getDescription() +
", Vendor: " +
info.getVendor());
output = MidiSystem.getMidiDevice(info);
if (! output.isOpen()) {
output.open();
}
}
}
} catch (MidiUnavailableException mue) {
mue.printStackTrace();
}
}
}
To run this from the command line choose a version of JDK you have installed, compile and run it with those specific versions substituting jdk1.7.0_80 for the distro you wish to test.
/opt/java-jdk/jdk1.7.0_80/bin/javac MidiInputTest.java
/opt/java-jdk/jdk1.7.0_80/bin/java -cp . MidiInputTest
Though I haven't been able to verify it, Java Sound is apparently responsible for figuring out what is available for java's use from your MIDI architecture.
Thank you Mike Harris for sending me down the right path of testing on the command line, and jim829 over at java-forums.org for the example code for the command line.
I had this problem which was caused by multiple instances of device info with the same name reterned by MidiSystem.getMidiDeviceInfo(). Basically when you call MidiSystem.getMidiDevice(Info) if you're unlucky it'll return the one without the transmitter. I'm not sure why it does this but only one instance has transmitters, (I think one might be for in and one out but, not sure). By first getting just the devices that have transmitters and then selecting from these, with the desired info, it worked for me. Hope that helps
public ArrayList<MidiDevice> getTransmitterDevices() {
MidiDevice.Info[] deviceInfo = MidiSystem.getMidiDeviceInfo();
ArrayList<MidiDevice> transmitterDevices = new ArrayList<>();
for(int i=0;i<deviceInfo.length;i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(deviceInfo[i]);
if(device.getMaxTransmitters()!=0) {
transmitterDevices.add(device);
}
} catch (MidiUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return transmitterDevices;
}
//Somewhere else
//choose appropriate info somehow
MidiDevices<ArrayList> transmitterDevices = getTransmitterDevices();
for(MidiDevice tmp : transmitterDevices) {
if(tmp.getDeviceInfo().equals(info)) {
try {
midiController = tmp;
Transmitter transmitter = midiController.getTransmitter();
// something that implements receiver
midiReceiver = new MidiReceiver();
transmitter.setReceiver(midiReceiver);
midiController.open();
System.out.println("controller set ok");
} catch (MidiUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

How to read recieved messages in j2me midlet using pushregistry?

i don't know how to read received messages in mobile device using J2ME midlet.Actually I have been sending the messages to other mobiles using SMS gateway.The sms gateway reply to the same mobile device,but i want to read the reply message on the device directly, not going to check the inbox.how to do this in j2me midlet using the PushRegistry concept.please give me the good idea or sample code for me...thanks in advance.
You should use the PushRegistry mechanism for this. In order to do so, you should mark in the .jad file that your application reacts to incoming SMS and also mark the SMS permission.
Put these properties to the JAD file:
MIDlet-Push-1: sms://:10214,hu.bute.daai.example.sms.MidletSMSPushDemo,*
MIDlet-Permissions: javax.microedition.io.PushRegistry, javax.microedition.io.Connector.sms, javax.wireless.messaging.sms.receive
Please note that you should use your own package and MIDlet name. In addition to that you should use the same port for SMS sending as it was defined in the JAD (10214 in the example).
After that when your MIDlet starts, you should call your SMS receiver code to get the SMS:
public class MidletJSMSProxy extends MIDlet {
public void startApp() {
initalize();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void initSMSReceive() {
new Thread() {
public void run() {
MessageConnection conn = null;
try {
String url = "sms://:10214";
MessageConnection conn = (MessageConnection) Connector.open(url);
TextMessage message = (TextMessage)conn.receive();
System.out.println("SMS: "+message.getAddress()+" - "+message.getPayloadText());
}
catch(Exception e){
e.printStackTrace();
} finally {
try {
if (conn != null)
conn.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
}.start();
}
}
More info:
http://www.developer.nokia.com/Community/Wiki/How_to_launch_a_MIDlet_remotely_via_SMS_or_locally_via_an_Alarm_with_PushRegistry_in_Java_ME

Receiving SMS sent from the WTK emulator in a custom application

I'm using Sun WTK to run a midlet that needs to send and optionally receive SMS. WMA console can be used to send and receive messages to the midlet but I'd like to do the same thing using my own application.
I have done some sniffing, and noticed that the messages are sent by UDP from the WMA console to the emulator.
After digging inside the jars in WTK I was able to figure out how to send and receive SMS. I had to include the jars kvem.jar and kenv.zip in the application classpath. Tested under Linux.
public static void main(String[] args) throws IOException, PhoneNumberNotAvailableException, InterruptedException {
System.setProperty("kvem.home", "/home/jassuncao/usr/WTK2.5.2");
WMAClient wmaClient = WMAClientFactory.newWMAClient(null, 4);
wmaClient.connect();
wmaClient.setMessageListener(new MessageListener() {
#Override
public void notifyIncomingMessage(WMAClient wmaclient) {
try {
System.out.println("Message received:"+wmaclient.receive());
} catch (IOException e) {
e.printStackTrace();
}
}
});
System.out.println("This number "+wmaClient.getPhoneNumber());
String[] receivers = wmaClient.getKnownReceivers();
for (String receiver : receivers) {
System.out.println("Sending SMS to "+receiver);
Message msg = new Message("Hello world!!");
msg.setFromAddress("sms://"+wmaClient.getPhoneNumber());
msg.setToAddress("sms://"+receiver);
//It seems the ports must be set AFTER the address to work
msg.setToPort(50000);
msg.setFromPort(50000);
wmaClient.send(msg);
}
System.in.read();
wmaClient.unregisterFromServer();
}

Categories

Resources