Compare commits
6 Commits
f111bd45b4
...
12a79edb5b
Author | SHA1 | Date | |
---|---|---|---|
12a79edb5b | |||
b7bdee4d29 | |||
e249b68e7f | |||
15728740c5 | |||
039827d078 | |||
3a3ec64eba |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@ -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>
|
|
@ -39,7 +39,7 @@
|
|||||||
android:name=".RestartService"
|
android:name=".RestartService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
<receiver android:name=".AlarmReceiver"/>
|
|
||||||
<receiver android:name=".RebootReceiver">
|
<receiver android:name=".RebootReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +1,7 @@
|
|||||||
package com.flywithu.carnav;
|
package com.flywithu.carnav;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -8,32 +10,26 @@ import android.content.IntentFilter;
|
|||||||
import android.hardware.usb.UsbDeviceConnection;
|
import android.hardware.usb.UsbDeviceConnection;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String SERVICECMD = "com.android.music.musicservicecommand";
|
|
||||||
public static final String TAG = "carnav";
|
|
||||||
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
|
|
||||||
private Intent serviceIntent;
|
private Intent serviceIntent;
|
||||||
|
public static final String SERVICECMD = "com.android.music.musicservicecommand";
|
||||||
|
public static final String TAG="carnav";
|
||||||
|
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
|
||||||
private BroadcastReceiver usbReceiver = null;
|
private BroadcastReceiver usbReceiver = null;
|
||||||
|
private void goService()
|
||||||
private void goService() {
|
{
|
||||||
|
|
||||||
|
|
||||||
if (RealService.serviceIntent == null) {
|
if (RealService.serviceIntent == null) {
|
||||||
|
|
||||||
serviceIntent = new Intent(this, RealService.class);
|
serviceIntent = new Intent(this, RealService.class);
|
||||||
startService(serviceIntent);
|
startService(serviceIntent);
|
||||||
Toast.makeText(getApplicationContext(), "new start", Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
} else {
|
||||||
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
|
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
|
||||||
Toast.makeText(getApplicationContext(), "already", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "already", Toast.LENGTH_LONG).show();
|
||||||
@ -50,13 +46,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||||
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
||||||
if (!availableDrivers.isEmpty()) {
|
if (!availableDrivers.isEmpty()) {
|
||||||
Toast.makeText(getApplicationContext(), "USB Exist", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(),"USB Exist",Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
UsbSerialDriver driver = null;
|
UsbSerialDriver driver = null;
|
||||||
UsbDeviceConnection connection = null;
|
UsbDeviceConnection connection = null;
|
||||||
try {
|
try {
|
||||||
driver = availableDrivers.get(0);
|
driver = availableDrivers.get(0);
|
||||||
if (!manager.hasPermission(driver.getDevice())) {
|
if(!manager.hasPermission(driver.getDevice()))
|
||||||
|
{
|
||||||
|
|
||||||
Toast.makeText(getApplicationContext(), "NO Permission", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "NO Permission", Toast.LENGTH_LONG).show();
|
||||||
//Request USB HOST
|
//Request USB HOST
|
||||||
@ -68,53 +65,64 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_ONE_SHOT);
|
new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_ONE_SHOT);
|
||||||
//
|
//
|
||||||
|
|
||||||
usbReceiver = new BroadcastReceiver() {
|
usbReceiver=new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (ACTION_USB_PERMISSION.equals(action)) {
|
if(ACTION_USB_PERMISSION.equals(action))
|
||||||
|
{
|
||||||
|
|
||||||
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true)) {
|
if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,true))
|
||||||
Toast.makeText(getApplicationContext(), "Pemission Granted", Toast.LENGTH_LONG).show();
|
{
|
||||||
|
Toast.makeText(getApplicationContext(), "Pemission Granted", Toast.LENGTH_LONG);
|
||||||
goService();
|
goService();
|
||||||
} else {
|
}
|
||||||
Toast.makeText(getApplicationContext(), "Pemission Denied", Toast.LENGTH_LONG).show();
|
else
|
||||||
|
{
|
||||||
|
Toast.makeText(getApplicationContext(), "Pemission Denied", Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerReceiver(usbReceiver, new IntentFilter(ACTION_USB_PERMISSION));
|
registerReceiver(usbReceiver, new IntentFilter(ACTION_USB_PERMISSION));
|
||||||
manager.requestPermission(driver.getDevice(), mPermissionIntent);
|
manager.requestPermission(driver.getDevice(), mPermissionIntent);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Toast.makeText(getApplicationContext(), "Has Permission", Toast.LENGTH_LONG).show();
|
}
|
||||||
|
else {
|
||||||
connection = manager.openDevice(driver.getDevice());
|
connection = manager.openDevice(driver.getDevice());
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG);
|
||||||
} else {
|
} 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();
|
goService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
} else {
|
catch(Exception e)
|
||||||
Toast.makeText(getApplicationContext(), "NO USB", Toast.LENGTH_LONG).show();
|
{
|
||||||
|
e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Toast.makeText(getApplicationContext(),"NO USB",Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -124,9 +132,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
stopService(serviceIntent);
|
stopService(serviceIntent);
|
||||||
serviceIntent = null;
|
serviceIntent = null;
|
||||||
}
|
}
|
||||||
if (usbReceiver != null) {
|
if(usbReceiver!=null)
|
||||||
|
{
|
||||||
unregisterReceiver(usbReceiver);
|
unregisterReceiver(usbReceiver);
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class MusicTitle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getTotal() {
|
public int getTotal() {
|
||||||
return 100;
|
return (total > 0) ? this.total : 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void setTotal(int total) {
|
//public void setTotal(int total) {
|
||||||
@ -54,11 +54,13 @@ public class MusicTitle {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(int position) {
|
public void setTotal(int total) {
|
||||||
this.position = position;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPosition(long position) {
|
||||||
|
this.position = (int) position;
|
||||||
|
}
|
||||||
|
|
||||||
public String getArtist() {
|
public String getArtist() {
|
||||||
if(artist == null)
|
if(artist == null)
|
||||||
|
@ -0,0 +1,143 @@
|
|||||||
|
package com.flywithu.carnav;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.media.MediaMetadata;
|
||||||
|
import android.media.session.MediaController;
|
||||||
|
import android.media.session.MediaSession;
|
||||||
|
import android.media.session.MediaSessionManager;
|
||||||
|
import android.media.session.PlaybackState;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.service.notification.NotificationListenerService;
|
||||||
|
import android.service.notification.StatusBarNotification;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@TargetApi(21)
|
||||||
|
public class NotificationListenerMusic extends NotificationListenerService {
|
||||||
|
String[] musicAppFilter = {"com.iloen.melon", "skplanet.musicmate"};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
ComponentName componentName = new ComponentName(this, getClass());
|
||||||
|
MediaSessionManager manager = (MediaSessionManager) this.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
||||||
|
|
||||||
|
manager.addOnActiveSessionsChangedListener(new MediaSessionManager.OnActiveSessionsChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onActiveSessionsChanged(@Nullable List<MediaController> controllers) {
|
||||||
|
for (MediaController controller : controllers) {
|
||||||
|
if (controllers != null) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
controller.registerCallback(new MediaController.Callback() {
|
||||||
|
MusicTitle currentSong = new MusicTitle();
|
||||||
|
|
||||||
|
private Intent getMusicIntent() {
|
||||||
|
Intent music = new Intent("com.flywithu.carnav.metachanged");
|
||||||
|
music.putExtra("artist", currentSong.getArtist());
|
||||||
|
music.putExtra("album", currentSong.getAlbum());
|
||||||
|
music.putExtra("track", currentSong.getTrack());
|
||||||
|
music.putExtra("playstate", currentSong.isRunning());
|
||||||
|
music.putExtra("position", currentSong.getPosition());
|
||||||
|
music.putExtra("total", currentSong.getTotal());
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onQueueChanged(List<MediaSession.QueueItem> queue) {
|
||||||
|
currentSong.setTotal(queue.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaybackStateChanged(@Nullable PlaybackState state) {
|
||||||
|
super.onPlaybackStateChanged(state);
|
||||||
|
currentSong.setRunning(state.getState() == PlaybackState.STATE_PLAYING);
|
||||||
|
currentSong.setPosition(state.getActiveQueueItemId());
|
||||||
|
Log.d("NotificationMusic", "Playback");
|
||||||
|
if (currentSong.getAlbum() != null) {
|
||||||
|
sendBroadcast(getMusicIntent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMetadataChanged(MediaMetadata metadata) {
|
||||||
|
super.onMetadataChanged(metadata);
|
||||||
|
currentSong.setArtist(metadata.getString(MediaMetadata.METADATA_KEY_ARTIST));
|
||||||
|
currentSong.setTrack(metadata.getString(MediaMetadata.METADATA_KEY_TITLE));
|
||||||
|
currentSong.setAlbum(metadata.getString(MediaMetadata.METADATA_KEY_ALBUM));
|
||||||
|
|
||||||
|
|
||||||
|
sendBroadcast(getMusicIntent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, componentName);
|
||||||
|
|
||||||
|
return super.onBind(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkMusicStatus() {
|
||||||
|
StatusBarNotification[] activeNotifications = getActiveNotifications();
|
||||||
|
for (StatusBarNotification noti : activeNotifications) {
|
||||||
|
if (Arrays.asList(musicAppFilter).contains(noti.getPackageName())) {
|
||||||
|
Notification mytest = noti.getNotification();
|
||||||
|
|
||||||
|
Bundle extras = noti.getNotification().extras;
|
||||||
|
|
||||||
|
|
||||||
|
for (String a : extras.keySet()) {
|
||||||
|
Object value = extras.get(a);
|
||||||
|
if (value instanceof Boolean) {
|
||||||
|
Log.d("NotificationListener", "KEY:" + extras.getBoolean(a));
|
||||||
|
} else if (value instanceof Integer) {
|
||||||
|
Log.d("NotificationListener", "KEY:" + extras.getInt(a));
|
||||||
|
} else {
|
||||||
|
Log.d("NotificationListener", "KEY:" + a + "/" + extras.getString(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// CharSequence title = extras.getString(Notification.EXTRA_TITLE);
|
||||||
|
// CharSequence artist = extras.getCharSequence(Notification.EXTRA_TEXT);
|
||||||
|
// Log.d("NotificationListener","NAME:"+noti.getPackageName());
|
||||||
|
// Log.i("NotificationListener", "[snowdeer] title:" + title);
|
||||||
|
// Log.i("NotificationListener", "[snowdeer] artist:" + artist);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Log.d("TAG",noti.getNotification().getGroup());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNotificationPosted(StatusBarNotification sbn) {
|
||||||
|
checkMusicStatus();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||||
|
checkMusicStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,9 @@ package com.flywithu.carnav;
|
|||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@ -10,12 +13,18 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.hardware.usb.UsbDeviceConnection;
|
import android.hardware.usb.UsbDeviceConnection;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
||||||
@ -33,100 +42,99 @@ public class RealService extends Service {
|
|||||||
public static Intent serviceIntent = null;
|
public static Intent serviceIntent = null;
|
||||||
|
|
||||||
private static UsbSerialPort sPort = null;
|
private static UsbSerialPort sPort = null;
|
||||||
private MusicTitle currentSong = new MusicTitle();
|
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String action = intent.getAction();
|
|
||||||
String cmd = intent.getStringExtra("command");
|
|
||||||
Log.v("MUSIC ", action + " / " + cmd);
|
|
||||||
String artist = intent.getStringExtra("artist");
|
|
||||||
String album = intent.getStringExtra("album");
|
|
||||||
String track = intent.getStringExtra("track");
|
|
||||||
Long myPosition = intent.getLongExtra("id", 1);
|
|
||||||
Log.v("MUSIC", artist + ":" + album + ":" + track);
|
|
||||||
boolean isRunning = intent.getBooleanExtra("playstate", false) | intent.getBooleanExtra("playing", false);
|
|
||||||
|
|
||||||
currentSong.setRunning(isRunning);
|
|
||||||
|
|
||||||
if (isRunning == true) {
|
|
||||||
currentSong.setAlbum(album);
|
|
||||||
currentSong.setArtist(artist);
|
|
||||||
currentSong.setTrack(track);
|
|
||||||
currentSong.setPosition(myPosition.intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public RealService() {
|
public RealService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSerial(String str) {
|
private void sendSerial(String str) {
|
||||||
|
|
||||||
sendSerial(str, Charset.forName("UTF-8"));
|
sendSerial(str,Charset.forName("UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void sendSerial(String str, Charset enc) {
|
private 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) {
|
if (sPort != null) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
int len = sPort.write(getStringToByte(str, enc), 3000);
|
|
||||||
|
sPort.write(getStringToByte(str,enc), 3000);
|
||||||
sPort.write(new byte[]{0xd}, 3000);
|
sPort.write(new byte[]{0xd}, 3000);
|
||||||
Log.d("TAG", 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) {
|
} catch (Exception e) {
|
||||||
showToast(getApplication(), "Error:" + e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
showToast(getApplication(), "SERIAL NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] getStringToByte(String str, Charset enc) {
|
}
|
||||||
ByteBuffer buf = ByteBuffer.allocate(150);
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected byte[] getStringToByte(String str,Charset enc)
|
||||||
|
{
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(100);;
|
||||||
|
/*
|
||||||
|
sendSerial("U4PL13|soar|");
|
||||||
|
sendSerial("U4PL23|헤어지자 (Prod. 정키)|");
|
||||||
|
sendSerial("U4PL33|휘인 (Whee In)|");
|
||||||
|
*/
|
||||||
String[] arrStr = null;
|
String[] arrStr = null;
|
||||||
if (str.startsWith("U4PL13") || str.startsWith("U4PL23") || str.startsWith("U4PL33")) {
|
if(str.startsWith("U4PL13")||str.startsWith("U4PL23")||str.startsWith("U4PL33"))
|
||||||
|
{
|
||||||
arrStr = str.split("\\|");
|
arrStr = str.split("\\|");
|
||||||
|
// System.out.println(arrStr[1]);
|
||||||
|
// System.out.println(arrStr[0]);
|
||||||
buf.put(arrStr[0].getBytes(Charset.forName("UTF-8")));
|
buf.put(arrStr[0].getBytes(Charset.forName("UTF-8")));
|
||||||
buf.put(new byte[]{0x7c});
|
buf.put(new byte[]{0x7c});
|
||||||
buf.put(arrStr[1].getBytes(enc));
|
buf.put(arrStr[1].getBytes(enc));
|
||||||
buf.put(new byte[]{0x7c});
|
buf.put(new byte[]{0x7c});
|
||||||
|
// System.out.println(new String(buf.array()));
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
} else {
|
|
||||||
buf.put(str.getBytes(Charset.forName("UTF-8")));
|
buf.put(str.getBytes(Charset.forName("UTF-8")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte[] bytes = new byte[buf.position()];
|
|
||||||
buf.flip();
|
|
||||||
buf.get(bytes);
|
|
||||||
|
|
||||||
|
|
||||||
return bytes;
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
serviceIntent = intent;
|
serviceIntent = intent;
|
||||||
showToast(getApplication(), "Start Service");
|
showToast(getApplication(), "Start Service");
|
||||||
|
|
||||||
|
//
|
||||||
|
// mainThread = new Thread(new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
|
||||||
|
|
||||||
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||||
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
List<UsbSerialDriver> availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
|
||||||
if (availableDrivers.isEmpty()) {
|
if (availableDrivers.isEmpty()) {
|
||||||
@ -134,11 +142,11 @@ public class RealService extends Service {
|
|||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open a connection to the first available driver.
|
||||||
UsbSerialDriver driver = null;
|
UsbSerialDriver driver = null;
|
||||||
UsbDeviceConnection connection = null;
|
UsbDeviceConnection connection = null;
|
||||||
try {
|
try {
|
||||||
driver = availableDrivers.get(0);
|
driver = availableDrivers.get(0);
|
||||||
|
|
||||||
connection = manager.openDevice(driver.getDevice());
|
connection = manager.openDevice(driver.getDevice());
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
showToast(getApplication(), "No connection");
|
showToast(getApplication(), "No connection");
|
||||||
@ -146,11 +154,8 @@ public class RealService extends Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
sPort = driver.getPorts().get(0);
|
sPort = driver.getPorts().get(0);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
showToast(getApplication(), e.toString());
|
showToast(getApplication(), e.toString());
|
||||||
return START_NOT_STICKY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -167,20 +172,63 @@ public class RealService extends Service {
|
|||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
sPort = null;
|
sPort = null;
|
||||||
return START_NOT_STICKY;
|
|
||||||
}
|
}
|
||||||
|
//set the time
|
||||||
|
//TMST001801140907
|
||||||
|
//TMST00YYDDDD0907
|
||||||
|
//TMST001205010916
|
||||||
SimpleDateFormat format1 = new SimpleDateFormat("00yyMMddHHmm");
|
SimpleDateFormat format1 = new SimpleDateFormat("00yyMMddHHmm");
|
||||||
// String f = format1.format(System.currentTimeMillis());
|
// String f = format1.format(System.currentTimeMillis());
|
||||||
String currentInfo = format1.format(new Date());
|
String currentInfo = format1.format(new Date());
|
||||||
String currentTime = String.format("TMST%s", currentInfo);
|
String currentTime = String.format("TMST%s", currentInfo);
|
||||||
sendSerial(currentTime);
|
sendSerial(currentTime);
|
||||||
sendSerial("U4EN00");
|
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)|
|
||||||
|
|
||||||
|
showToast(getApplication(), currentTime);
|
||||||
|
|
||||||
|
// 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();
|
IntentFilter iF = new IntentFilter();
|
||||||
iF.addAction("com.android.music.metachanged");
|
iF.addAction("com.android.music.metachanged");
|
||||||
|
|
||||||
iF.addAction("com.htc.music.metachanged");
|
iF.addAction("com.htc.music.metachanged");
|
||||||
|
|
||||||
iF.addAction("fm.last.android.metachanged");
|
iF.addAction("fm.last.android.metachanged");
|
||||||
iF.addAction("com.sec.android.app.music.metachanged");
|
iF.addAction("com.sec.android.app.music.metachanged");
|
||||||
iF.addAction("com.nullsoft.winamp.metachanged");
|
iF.addAction("com.nullsoft.winamp.metachanged");
|
||||||
@ -195,54 +243,7 @@ public class RealService extends Service {
|
|||||||
iF.addAction("com.android.music.playstatechanged");
|
iF.addAction("com.android.music.playstatechanged");
|
||||||
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;
|
|
||||||
int stopCount = 0;
|
|
||||||
while (myRun) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
Thread.sleep(5000);
|
|
||||||
SimpleDateFormat format1 = new SimpleDateFormat("00yyMMddHHmm");
|
|
||||||
String currentInfo = format1.format(new Date());
|
|
||||||
String currentTime = String.format("TMST%s", currentInfo);
|
|
||||||
sendSerial(currentTime);
|
|
||||||
|
|
||||||
if (currentSong.isRunning()) {
|
|
||||||
stopCount = 0;
|
|
||||||
sendSerial("U4EN00");
|
|
||||||
sendSerial("U4OP00");
|
|
||||||
sendSerial("U4PL03|" + currentSong.getTotal() + "," + currentSong.getPosition() + "|0001010000000");
|
|
||||||
sendSerial("U4PL13|" + currentSong.getAlbum() + "|", Charset.forName("UTF-8"));
|
|
||||||
sendSerial("U4PL23|" + currentSong.getTrack() + "|", Charset.forName("UTF-8"));
|
|
||||||
sendSerial("U4PL33|" + currentSong.getArtist() + "|", Charset.forName("UTF-8"));
|
|
||||||
} else {
|
|
||||||
if (stopCount > 5) {
|
|
||||||
sendSerial("U4DI00");
|
|
||||||
}
|
|
||||||
stopCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
myRun = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,14 +254,15 @@ public class RealService extends Service {
|
|||||||
sPort.close();
|
sPort.close();
|
||||||
sPort = null;
|
sPort = null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
showToast(getApplication(), "stop Error");
|
|
||||||
}
|
}
|
||||||
serviceIntent = null;
|
serviceIntent = null;
|
||||||
setAlarmTimer();
|
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
unregisterReceiver(mReceiver);
|
unregisterReceiver(mReceiver);
|
||||||
showToast(getApplication(), "stop Service");
|
// if (mainThread != null) {
|
||||||
|
// mainThread.interrupt();
|
||||||
|
// mainThread = null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -283,21 +285,101 @@ public class RealService extends Service {
|
|||||||
h.post(new Runnable() {
|
h.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(application, msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(application, msg, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAlarmTimer() {
|
|
||||||
final Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeInMillis(System.currentTimeMillis());
|
|
||||||
c.add(Calendar.SECOND, 1);
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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("MUSIC ", action + " / " + cmd);
|
||||||
|
String artist = intent.getStringExtra("artist");
|
||||||
|
String album = intent.getStringExtra("album");
|
||||||
|
String track = intent.getStringExtra("track");
|
||||||
|
Log.v("MUSIC", artist + ":" + album + ":" + track);
|
||||||
|
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
// }
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ import android.os.Build;
|
|||||||
public class RebootReceiver extends BroadcastReceiver {
|
public class RebootReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
Intent in = new Intent(context, RestartService.class);
|
Intent in = new Intent(context, RestartService.class);
|
||||||
context.startForegroundService(in);
|
context.startForegroundService(in);
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package com.flywithu.carnav;
|
|
||||||
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
|
|
||||||
public class RestartService extends Service {
|
|
||||||
public RestartService() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "default");
|
|
||||||
builder.setSmallIcon(R.mipmap.ic_launcher);
|
|
||||||
builder.setContentTitle(null);
|
|
||||||
builder.setContentText(null);
|
|
||||||
Intent notificationIntent = new Intent(this, MainActivity.class);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
|
||||||
builder.setContentIntent(pendingIntent);
|
|
||||||
|
|
||||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
manager.createNotificationChannel(new NotificationChannel("default", "기본 채널", NotificationManager.IMPORTANCE_NONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification notification = builder.build();
|
|
||||||
startForeground(9, notification);
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
Intent in = new Intent(this, RealService.class);
|
|
||||||
startService(in);
|
|
||||||
|
|
||||||
stopForeground(true);
|
|
||||||
stopSelf();
|
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onUnbind(Intent intent) {
|
|
||||||
return super.onUnbind(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +1,40 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/textViewNotification"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Hello World!"
|
android:text="Permission Notification" />
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
<TextView
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
android:id="@+id/textViewNotificationStatus"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Permission Notification" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewUSB"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Permission USB" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewUSBStatus"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Permission USB" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -3,7 +3,6 @@ package com.flywithu.carnav;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -58,20 +57,13 @@ public class ExampleUnitTest {
|
|||||||
public void checkout()
|
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
|
//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 = "오";
|
String test = "A지어반Z";
|
||||||
//EC A7 80 EC 96 B4 EB B0 98
|
//EC A7 80 EC 96 B4 EB B0 98
|
||||||
|
|
||||||
//오
|
|
||||||
//오
|
|
||||||
// ec98a4
|
|
||||||
//feffc624
|
|
||||||
//0000c624
|
|
||||||
System.out.println(test);
|
System.out.println(test);
|
||||||
try {
|
try {
|
||||||
System.out.println(bytesToHex(test.getBytes("utf-8")));
|
System.out.println(bytesToHex(test.getBytes("utf-8")));
|
||||||
System.out.println(bytesToHex(test.getBytes("utf-16")));
|
System.out.println(bytesToHex(test.getBytes("utf-16")));
|
||||||
System.out.println(bytesToHex(test.getBytes("utf-32")));
|
System.out.println(bytesToHex(test.getBytes("utf-32")));
|
||||||
System.out.println(new String(new byte[]{0x0,(byte)0xec,0x0,(byte)0x98,0x0,(byte)0xa4}, StandardCharsets.UTF_16));
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user