update for thread
This commit is contained in:
parent
2996270628
commit
775a655692
@ -53,7 +53,7 @@ public class RealService extends Service {
|
|||||||
sendSerial(str,Charset.forName("UTF-8"));
|
sendSerial(str,Charset.forName("UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSerial(String str,Charset enc) {
|
private synchronized void sendSerial(String str,Charset enc) {
|
||||||
byte t1[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x30, 0x33, 0x7C, 0x31, 0x2C, 0x31, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30};
|
byte t1[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x30, 0x33, 0x7C, 0x31, 0x2C, 0x31, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30};
|
||||||
byte t2[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x31, 0x33, 0x7C, 0x41, (byte) 0xec, (byte) 0xa7, (byte) 0x80, (byte) 0xec, (byte) 0x96, (byte) 0xb4, (byte) 0xeb, (byte) 0xb0, (byte) 0x98, 0x5a, 0x7c};
|
byte t2[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x31, 0x33, 0x7C, 0x41, (byte) 0xec, (byte) 0xa7, (byte) 0x80, (byte) 0xec, (byte) 0x96, (byte) 0xb4, (byte) 0xeb, (byte) 0xb0, (byte) 0x98, 0x5a, 0x7c};
|
||||||
byte t3[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x32, 0x33, 0x7C, (byte) 0xfe, (byte) 0xff, 0x00, 0x41, (byte) 0xc9, (byte) 0xc0, (byte) 0xc5, (byte) 0xb4, (byte) 0xbc, 0x18, 0x00, 0x5a, 0x7c};
|
byte t3[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x32, 0x33, 0x7C, (byte) 0xfe, (byte) 0xff, 0x00, 0x41, (byte) 0xc9, (byte) 0xc0, (byte) 0xc5, (byte) 0xb4, (byte) 0xbc, 0x18, 0x00, 0x5a, 0x7c};
|
||||||
@ -244,6 +244,37 @@ feff0041c9c0c5b4bc18005a
|
|||||||
iF.addAction("com.android.music.playbackcomplete");
|
iF.addAction("com.android.music.playbackcomplete");
|
||||||
iF.addAction("com.android.music.queuechanged");
|
iF.addAction("com.android.music.queuechanged");
|
||||||
registerReceiver(mReceiver, iF);
|
registerReceiver(mReceiver, iF);
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
|
||||||
|
boolean myRun = true;
|
||||||
|
while (myRun)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(1000);
|
||||||
|
SimpleDateFormat format1 = new SimpleDateFormat("00yyMMddHHmm");
|
||||||
|
// String f = format1.format(System.currentTimeMillis());
|
||||||
|
String currentInfo = format1.format(new Date());
|
||||||
|
String currentTime = String.format("TMST%s", currentInfo);
|
||||||
|
sendSerial(currentTime);
|
||||||
|
showToast(getApplication(), currentTime);
|
||||||
|
}
|
||||||
|
catch(InterruptedException e)
|
||||||
|
{
|
||||||
|
myRun = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,31 +396,4 @@ feff0041c9c0c5b4bc18005a
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// private void sendNotification(String messageBody) {
|
|
||||||
// Intent intent = new Intent(this, MainActivity.class);
|
|
||||||
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
|
|
||||||
//
|
|
||||||
// String channelId = "fcm_default_channel";//getString(R.string.default_notification_channel_id);
|
|
||||||
// Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
||||||
// NotificationCompat.Builder notificationBuilder =
|
|
||||||
// new NotificationCompat.Builder(this, channelId)
|
|
||||||
// .setSmallIcon(R.mipmap.ic_launcher)//drawable.splash)
|
|
||||||
// .setContentTitle("Service test")
|
|
||||||
// .setContentText(messageBody)
|
|
||||||
// .setAutoCancel(true)
|
|
||||||
// .setSound(defaultSoundUri)
|
|
||||||
// .setPriority(Notification.PRIORITY_HIGH)
|
|
||||||
// .setContentIntent(pendingIntent);
|
|
||||||
//
|
|
||||||
// NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
//
|
|
||||||
// // Since android Oreo notification channel is needed.
|
|
||||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
// NotificationChannel channel = new NotificationChannel(channelId,"Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
|
|
||||||
// notificationManager.createNotificationChannel(channel);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
|
|
||||||
// }
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user