Compare commits

...

9 Commits

Author SHA1 Message Date
53a6431453 Correct using bytearray. 2019-09-15 09:21:17 +09:00
27814e5a8e test for. 2019-09-13 01:23:41 +09:00
effa89e030 RealService 2019-09-08 23:54:35 +09:00
775a655692 update for thread 2019-09-08 23:51:57 +09:00
2996270628 new 2019-09-08 18:21:08 +09:00
ea3fb56ee2 3rd commit - made basic skeleton 2019-09-08 14:34:46 +09:00
31b0eea4e2 3rd commit - made basic skeleton 2019-09-07 12:18:21 +09:00
3d2fe9eb5a second commit 2019-09-05 23:48:52 +09:00
91b1ff2a93 FirstCommit 2019-08-31 17:54:58 +09:00
8 changed files with 531 additions and 167 deletions

2
.idea/misc.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -2,6 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flywithu.carnav"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-feature android:name="android.hardware.usb.host" />
<application
android:allowBackup="true"
@ -27,12 +32,24 @@
android:resource="@xml/device_filter" />
</service>
<service
android:name=".RestartService"
android:enabled="true"
android:exported="true" />
<receiver android:name=".AlarmReceiver"/>
<receiver android:name=".RebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-sdk tools:overrideLibrary="com.hoho.android.usbserial"/>
</manifest>

View File

@ -1,21 +1,21 @@
package com.flywithu.carnav;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
public class AlarmRecever extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent in = new Intent(context, RestartService.class);
context.startForegroundService(in);
} else {
Intent in = new Intent(context, RealService.class);
context.startService(in);
}
}
}
package com.flywithu.carnav;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
public class AlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent in = new Intent(context, RestartService.class);
context.startForegroundService(in);
} else {
Intent in = new Intent(context, RealService.class);
context.startService(in);
}
}
}

View File

@ -2,35 +2,145 @@ package com.flywithu.carnav;
import androidx.appcompat.app.AppCompatActivity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.hoho.android.usbserial.driver.UsbSerialDriver;
import com.hoho.android.usbserial.driver.UsbSerialPort;
import com.hoho.android.usbserial.driver.UsbSerialProber;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Intent serviceIntent;
public static final String SERVICECMD = "com.android.music.musicservicecommand";
public static final String TAG="carnav";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
private BroadcastReceiver usbReceiver = null;
private void goService()
{
if (RealService.serviceIntent == null) {
if (RealService.serviceIntent==null) {
serviceIntent = new Intent(this, RealService.class);
startService(serviceIntent);
Toast.makeText(getApplicationContext(), "new start", Toast.LENGTH_LONG).show();
} else {
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
Toast.makeText(getApplicationContext(), "already", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (!availableDrivers.isEmpty()) {
Toast.makeText(getApplicationContext(),"USB Exist",Toast.LENGTH_LONG).show();
UsbSerialDriver driver = null;
UsbDeviceConnection connection = null;
try {
driver = availableDrivers.get(0);
if(!manager.hasPermission(driver.getDevice()))
{
Toast.makeText(getApplicationContext(), "NO Permission", Toast.LENGTH_LONG).show();
//Request USB HOST
// You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
if (!manager.hasPermission(driver.getDevice())) {
PendingIntent mPermissionIntent;
mPermissionIntent = PendingIntent.getBroadcast(MainActivity.this, 0,
new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_ONE_SHOT);
//
usbReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(ACTION_USB_PERMISSION.equals(action))
{
if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,true))
{
Toast.makeText(getApplicationContext(), "Pemission Granted", Toast.LENGTH_LONG).show();
goService();
}
else
{
Toast.makeText(getApplicationContext(), "Pemission Denied", Toast.LENGTH_LONG).show();
}
}
}
};
registerReceiver(usbReceiver, new IntentFilter(ACTION_USB_PERMISSION));
manager.requestPermission(driver.getDevice(), mPermissionIntent);
}
}
else {
Toast.makeText(getApplicationContext(), "Has Permission", Toast.LENGTH_LONG).show();
connection = manager.openDevice(driver.getDevice());
if (connection == null) {
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG).show();
} else {
UsbSerialPort sPort = null;
sPort = driver.getPorts().get(0);
sPort.open(connection);
Toast.makeText(getApplicationContext(),"Serial Count:"+String.valueOf(driver.getPorts().size()),Toast.LENGTH_LONG).show();
sPort.close();
sPort = null;
goService();
}
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"NO USB",Toast.LENGTH_LONG).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -38,6 +148,9 @@ public class MainActivity extends AppCompatActivity {
stopService(serviceIntent);
serviceIntent = null;
}
}
if(usbReceiver!=null)
{
unregisterReceiver(usbReceiver);
}}
}

View File

@ -16,6 +16,7 @@ import android.hardware.usb.UsbManager;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@ -29,21 +30,115 @@ import com.hoho.android.usbserial.driver.UsbSerialPort;
import com.hoho.android.usbserial.driver.UsbSerialProber;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class RealService extends Service {
// private Thread mainThread;
// private Thread mainThread;
public static Intent serviceIntent = null;
private static UsbSerialPort sPort = null;
public RealService() {
}
private void sendSerial(String str) {
sendSerial(str,Charset.forName("UTF-8"));
}
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 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 t4[] = new byte[]{0x55, 0x34, 0x50, 0x4C, 0x33, 0x33, 0x7C, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, (byte) 0xc9, (byte) 0xc0, 0x00, 0x00, (byte) 0xc5, (byte) 0xb4, 0x00, 0x00, (byte) 0xbc, 0x18, 0x00, 0x00, 0x00, 0x5a, 0x7c};
/*
41eca780ec96b4ebb0985a
feff0041c9c0c5b4bc18005a
000000410000c9c00000c5b40000bc180000005a
*/
if (sPort != null) {
try {
sPort.write(getStringToByte(str,enc), 3000);
// Toast.makeText(getApplicationContext(),String.valueOf(result),Toast.LENGTH_SHORT).show();
sPort.write(new byte[]{0xd}, 3000);
// Toast.makeText(getApplicationContext(),String.valueOf(result2),Toast.LENGTH_SHORT).show();
Log.d("TAG",str);
// showToast(getApplication(), "SEND:"+str);
// sPort.write(t1, 3000);
// sPort.write(new byte[]{0xd}, 3000);
//
// sPort.write(t2, 3000);
// sPort.write(new byte[]{0xd}, 3000);
//
// sPort.write(t3, 3000);
// sPort.write(new byte[]{0xd}, 3000);
//
// sPort.write(t4, 3000);
// sPort.write(new byte[]{0xd}, 3000);
} catch (Exception e) {
showToast(getApplication(),"Error:"+e.toString());
}
}
else
{
showToast(getApplication(),"SERIAL NULL");
}
}
protected byte[] getStringToByte(String str,Charset enc)
{
ByteBuffer buf = ByteBuffer.allocate(300);;
/*
sendSerial("U4PL13|soar|");
sendSerial("U4PL23|헤어지자 (Prod. 정키)|");
sendSerial("U4PL33|휘인 (Whee In)|");
*/
String[] arrStr = null;
if(str.startsWith("U4PL13")||str.startsWith("U4PL23")||str.startsWith("U4PL33"))
{
arrStr = str.split("\\|");
// System.out.println(arrStr[1]);
// System.out.println(arrStr[0]);
buf.put(arrStr[0].getBytes(Charset.forName("UTF-8")));
buf.put(new byte[]{0x7c});
buf.put(arrStr[1].getBytes(enc));
// Log.d("TAG", String.valueOf( buf.position()));
buf.put(new byte[]{0x7c});
// System.out.println(new String(buf.array()));
// Log.d("TAG", String.valueOf( buf.position()));
}
else
{
buf.put(str.getBytes(Charset.forName("UTF-8")));
}
byte[] bytes = new byte[buf.position()];
buf.get(bytes,0,buf.position());
return bytes;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
serviceIntent = intent;
@ -55,74 +150,78 @@ public class RealService extends Service {
// public void run() {
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (availableDrivers.isEmpty()) {
showToast(getApplication(), "NO SERIAL");
return START_NOT_STICKY;
}
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (availableDrivers.isEmpty()) {
showToast(getApplication(), "NO SERIAL");
return START_NOT_STICKY;
}
// Open a connection to the first available driver.
UsbSerialDriver driver = null;
UsbDeviceConnection connection = null;
try {
driver = availableDrivers.get(0);
connection = manager.openDevice(driver.getDevice());
if (connection == null) {
showToast(getApplication(), "No connection");
// You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
return START_NOT_STICKY;
}
}
catch(Exception e)
{
showToast(getApplication(),e.toString());
}
UsbSerialDriver driver = null;
UsbDeviceConnection connection = null;
try {
driver = availableDrivers.get(0);
try {
sPort.open(connection);
sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
connection = manager.openDevice(driver.getDevice());
if (connection == null) {
showToast(getApplication(), "No connection");
return START_NOT_STICKY;
}
sPort = driver.getPorts().get(0);
// showToast(getApplication(), driver.getDevice().getProductName());
} catch (Exception e) {
showToast(getApplication(), e.toString());
return START_NOT_STICKY;
}
try {
sPort.open(connection);
sPort.setParameters(19200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
} catch (IOException e) {
showToast(getApplication(), "Error opening device: " + e.getMessage());
try {
sPort.close();
} catch (IOException e2) {
// Ignore.
}
sPort = null;
return START_NOT_STICKY;
}
//set the time
//TMST001801140907
//TMST00YYDDDD0907
//TMST001205010916
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);
sendSerial("U4EN00");
sendSerial("*R|R1R2R3D1D2A1A3U4|");
sendSerial("U4PL03|5,3|0001010000000");
sendSerial("U4PL13|8소아|",Charset.forName("UTF-8"));
sendSerial("U4PL23|16헤어지자 (Prod. 정키)|", Charset.forName("UTF-16"));
sendSerial("U4PL33|32휘인 (Whee In)|",Charset.forName("UTF-32"));
// sendSerial("U4DI00");
// sendSerial("*R|R1R2R3D1D2A1A3|");
// U4EN00
// *R|R1R2R3D1D2A1A3U4|
// A1PL00
//U4PL03|1,1|0001010000000 U4PL13|soar| U4PL23|헤어지자 (Prod. 정키)| U4PL33|휘인 (Whee In)|
} catch (IOException e) {
showToast(getApplication(),"Error opening device: " + e.getMessage());
try {
sPort.close();
} catch (IOException e2) {
// Ignore.
}
sPort = null;
}
//set the time
// try {
// sPort.write("zxcv".getBytes(), 50);
// }
// catch(Exception e)
// {
//
// }
// SimpleDateFormat sdf = new SimpleDateFormat("aa hh:mm");
// boolean run = true;
// while (run) {
// try {
// Thread.sleep(1000 * 60 * 1); // 1 minute
// Date date = new Date();
// //showToast(getApplication(), sdf.format(date));
// sendNotification(sdf.format(date));
// } catch (InterruptedException e) {
// run = false;
// e.printStackTrace();
// }
// }
// }
// });
// mainThread.start();
IntentFilter iF = new IntentFilter();
iF.addAction("com.android.music.metachanged");
@ -138,8 +237,93 @@ public class RealService extends Service {
iF.addAction("com.rdio.android.metachanged");
iF.addAction("com.samsung.sec.android.MusicPlayer.metachanged");
iF.addAction("com.andrew.apollo.metachanged");
iF.addAction("com.android.music.metachanged");
iF.addAction("com.android.music.playstatechanged");
iF.addAction("com.android.music.playbackcomplete");
iF.addAction("com.android.music.queuechanged");
registerReceiver(mReceiver, iF);
new Thread(new Runnable() {
@Override
public void run()
{
boolean myRun = true;
while (myRun)
{
try
{
Thread.sleep(5000);
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);
sendSerial("U4EN00");
sendSerial("*R|R1R2R3D1D2A1A3U4|");
sendSerial("U4PL03|5,3|0001010000000");
sendSerial("U4PL13|8소아|",Charset.forName("UTF-8"));
sendSerial("U4PL23|16헤어지자 (Prod. 정키)|", Charset.forName("UTF-16"));
sendSerial("U4PL33|32휘인 (Whee In)|",Charset.forName("UTF-32"));
}
catch(InterruptedException e)
{
myRun = false;
}
}
}
}).start();
// new Thread(new Runnable() {
// @Override
// public void run()
// {
//
// boolean myRun = true;
// showToast(getApplication(), "READ start");
// while (myRun)
// {
// try
// {
// byte[] mArray = new byte[100];
// int len = sPort.read(mArray,1000);
// if(len >0)
// {
// String result = new String (mArray,0,len,Charset.defaultCharset());
// showToast(getApplication(), "READ:"+result);
// }
// else
// {
// showToast(getApplication(), "READ FAIL");
// Log.d("FAIL","FAIL");
// }
//
//
// }
// catch(Exception e)
// {
// myRun = false;
//
// }
// }
//
// }
//
// }).start();
return START_NOT_STICKY;
}
@ -149,15 +333,14 @@ public class RealService extends Service {
try {
sPort.close();
sPort = null;
}
catch(Exception e)
{
} catch (Exception e) {
showToast(getApplication(),"stop Error");
}
serviceIntent = null;
setAlarmTimer();
Thread.currentThread().interrupt();
unregisterReceiver(mReceiver);
showToast(getApplication(),"stop Service");
// if (mainThread != null) {
// mainThread.interrupt();
// mainThread = null;
@ -184,7 +367,7 @@ public class RealService extends Service {
h.post(new Runnable() {
@Override
public void run() {
Toast.makeText(application, msg, Toast.LENGTH_LONG).show();
Toast.makeText(application, msg, Toast.LENGTH_SHORT).show();
}
});
}
@ -193,70 +376,68 @@ public class RealService extends Service {
final Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.add(Calendar.SECOND, 1);
Intent intent = new Intent(this, AlarmRecever.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0,intent,0);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (sPort != null)
{
sPort.write("abc".getBytes(), 3000);
Bundle bundle = intent.getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d("MUSIC", String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
catch(Exception e)
{
e.toString();
}
/*
2019-09-07 11:47:50.244 7675-7675/com.flywithu.carnav D/MUSIC: artist 없음 (java.lang.String)
2019-09-07 11:47:50.244 7675-7675/com.flywithu.carnav D/MUSIC: albumId 11 (java.lang.Long)
2019-09-07 11:47:50.244 7675-7675/com.flywithu.carnav D/MUSIC: playing true (java.lang.Boolean)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: id 50 (java.lang.String)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: album Download (java.lang.String)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: track I understand (2) (java.lang.String)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: vi_direction 2 (java.lang.Long)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: listPosition 2 (java.lang.Long)
2019-09-07 11:47:50.245 7675-7675/com.flywithu.carnav D/MUSIC: mediaCount 2 (java.lang.Long)
2019-09-07 11:50:45.186 7675-7675/com.flywithu.carnav D/MUSIC: duration 60000 (java.lang.Long)
2019-09-07 11:50:45.186 7675-7675/com.flywithu.carnav D/MUSIC: playstate true (java.lang.Boolean)
2019-09-07 11:50:45.187 7675-7675/com.flywithu.carnav D/MUSIC: artist 거미 (java.lang.String)
2019-09-07 11:50:45.187 7675-7675/com.flywithu.carnav D/MUSIC: albumId 10314289 (java.lang.String)
2019-09-07 11:50:45.188 7675-7675/com.flywithu.carnav D/MUSIC: playing true (java.lang.Boolean)
2019-09-07 11:50:45.188 7675-7675/com.flywithu.carnav D/MUSIC: id 1 (java.lang.Long)
2019-09-07 11:50:45.189 7675-7675/com.flywithu.carnav D/MUSIC: album 호텔 델루나 OST Part.7 (java.lang.String)
2019-09-07 11:50:45.189 7675-7675/com.flywithu.carnav D/MUSIC: track 기억해줘요 모든 날과 그때를 - 거미 (java.lang.String)
2019-09-07 11:50:45.189 7675-7675/com.flywithu.carnav V/tag: com.android.music.metachanged / null
2019-09-07 11:50:45.189 7675-7675/com.flywithu.carnav V/MUSIC: 거미:호텔 델루나 OST Part.7:기억해줘요 모든 날과 그때를 - 거미
2019-09-07 12:15:16.312 19489-19489/com.flywithu.carnav D/MUSIC: position 38119 (java.lang.Long)
2019-09-07 12:15:16.312 19489-19489/com.flywithu.carnav D/MUSIC: trackLength 162923 (java.lang.Long)
2019-09-07 12:15:16.312 19489-19489/com.flywithu.carnav D/MUSIC: trackLength 162923 (java.lang.Long)
*/
String action = intent.getAction();
String cmd = intent.getStringExtra("command");
Log.v("tag ", action + " / " + cmd);
Log.v("MUSIC ", action + " / " + cmd);
String artist = intent.getStringExtra("artist");
String album = intent.getStringExtra("album");
String track = intent.getStringExtra("track");
Log.v("tag", artist + ":" + album + ":" + track);
Log.v("MUSIC", artist + ":" + album + ":" + track);
// Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show();
// Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show();
}
};
// 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());
// }
}

View File

@ -1,19 +1,21 @@
package com.flywithu.carnav;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
public class RebootRecever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent in = new Intent(context, RestartService.class);
context.startForegroundService(in);
} else {
Intent in = new Intent(context, RealService.class);
context.startService(in);
}
}
package com.flywithu.carnav;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.widget.Toast;
public class RebootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent in = new Intent(context, RestartService.class);
context.startForegroundService(in);
} else {
Intent in = new Intent(context, RealService.class);
context.startService(in);
}
}
}

View File

@ -2,6 +2,11 @@ package com.flywithu.carnav;
import org.junit.Test;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import static org.junit.Assert.*;
/**
@ -14,4 +19,56 @@ public class ExampleUnitTest {
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
@Test
public void checkDate()
{
LocalDateTime currentDateTime = LocalDateTime.now();
//TMST001801140907
//TMST00YYDDDD0907
Date myDate = new Date ( "Sun,5 Dec 1999 00:07:21" );
SimpleDateFormat format1 = new SimpleDateFormat ( "yy MM dd HH mm");
// String f = format1.format(System.currentTimeMillis());
String f = format1.format(myDate);
System.out.println(f);
}
private static String bytesToHex(byte[] hashInBytes) {
StringBuilder sb = new StringBuilder();
for (byte b : hashInBytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
@Test
public void myTest()
{
RealService rs = new RealService();
rs.getStringToByte("U4PL23|헤어지자 (Prod. 정키)|", Charset.forName("UTF-8"));
}
@Test
public void checkout()
{
//55 34 50 4C 33 33 7C ED 9C 98 EC 9D B8 20 28 57 68 65 65 20 49 6E 29 7C 0D
String test = "A지어반Z";
//EC A7 80 EC 96 B4 EB B0 98
System.out.println(test);
try {
System.out.println(bytesToHex(test.getBytes("utf-8")));
System.out.println(bytesToHex(test.getBytes("utf-16")));
System.out.println(bytesToHex(test.getBytes("utf-32")));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}