Oreo
This commit is contained in:
parent
f111bd45b4
commit
3a3ec64eba
@ -34,18 +34,21 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<service
|
|
||||||
android:name=".RestartService"
|
|
||||||
android:enabled="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"/>
|
||||||
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="android.intent.action.SCREEN_ON" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".NotificationListenerMusic"
|
||||||
|
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.notification.NotificationListenerService" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -8,15 +8,18 @@ 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.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -41,12 +44,41 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isNotiPermissionAllowed() {
|
||||||
|
Set<String> notiListenerSet = NotificationManagerCompat.getEnabledListenerPackages(this);
|
||||||
|
String myPackageName = getPackageName();
|
||||||
|
|
||||||
|
for (String packageName : notiListenerSet) {
|
||||||
|
if (packageName == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (packageName.equals(myPackageName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
|
||||||
|
boolean isPermissionAllowed = isNotiPermissionAllowed();
|
||||||
|
|
||||||
|
if (!isPermissionAllowed) {
|
||||||
|
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
((TextView) findViewById(R.id.textViewNotificationStatus)).setText((isNotiPermissionAllowed()) ? "OK" : "NO");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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()) {
|
||||||
@ -99,11 +131,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
UsbSerialPort sPort = null;
|
UsbSerialPort sPort = null;
|
||||||
sPort = driver.getPorts().get(0);
|
sPort = driver.getPorts().get(0);
|
||||||
sPort.open(connection);
|
sPort.open(connection);
|
||||||
Toast.makeText(getApplicationContext(), "Serial Count:" + String.valueOf(driver.getPorts().size()), Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "Serial Count:" + driver.getPorts().size(), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
sPort.close();
|
sPort.close();
|
||||||
sPort = null;
|
|
||||||
|
|
||||||
|
|
||||||
goService();
|
goService();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,9 @@
|
|||||||
package com.flywithu.carnav;
|
package com.flywithu.carnav;
|
||||||
|
|
||||||
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 +12,15 @@ 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.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;
|
||||||
@ -24,7 +29,6 @@ import java.io.IOException;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -34,6 +38,7 @@ public class RealService extends Service {
|
|||||||
|
|
||||||
private static UsbSerialPort sPort = null;
|
private static UsbSerialPort sPort = null;
|
||||||
private MusicTitle currentSong = new MusicTitle();
|
private MusicTitle currentSong = new MusicTitle();
|
||||||
|
Boolean oldmethod = true;
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,6 +55,11 @@ public class RealService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
if (action.startsWith("com.flywithu")) {
|
||||||
|
oldmethod = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldmethod == true) {
|
||||||
String cmd = intent.getStringExtra("command");
|
String cmd = intent.getStringExtra("command");
|
||||||
Log.v("MUSIC ", action + " / " + cmd);
|
Log.v("MUSIC ", action + " / " + cmd);
|
||||||
String artist = intent.getStringExtra("artist");
|
String artist = intent.getStringExtra("artist");
|
||||||
@ -58,7 +68,6 @@ public class RealService extends Service {
|
|||||||
Long myPosition = intent.getLongExtra("id", 1);
|
Long myPosition = intent.getLongExtra("id", 1);
|
||||||
Log.v("MUSIC", artist + ":" + album + ":" + track);
|
Log.v("MUSIC", artist + ":" + album + ":" + track);
|
||||||
boolean isRunning = intent.getBooleanExtra("playstate", false) | intent.getBooleanExtra("playing", false);
|
boolean isRunning = intent.getBooleanExtra("playstate", false) | intent.getBooleanExtra("playing", false);
|
||||||
|
|
||||||
currentSong.setRunning(isRunning);
|
currentSong.setRunning(isRunning);
|
||||||
|
|
||||||
if (isRunning == true) {
|
if (isRunning == true) {
|
||||||
@ -67,10 +76,39 @@ public class RealService extends Service {
|
|||||||
currentSong.setTrack(track);
|
currentSong.setTrack(track);
|
||||||
currentSong.setPosition(myPosition.intValue());
|
currentSong.setPosition(myPosition.intValue());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
currentSong.setAlbum(intent.getStringExtra("album"));
|
||||||
|
currentSong.setArtist(intent.getStringExtra("artist"));
|
||||||
|
currentSong.setTrack(intent.getStringExtra("track"));
|
||||||
|
currentSong.setPosition(0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void setNotification() {
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public RealService() {
|
public RealService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +233,9 @@ 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");
|
||||||
|
iF.addAction("com.flywithu.carnav.metachanged");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerReceiver(mReceiver, iF);
|
registerReceiver(mReceiver, iF);
|
||||||
@ -243,7 +284,7 @@ public class RealService extends Service {
|
|||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -256,7 +297,6 @@ public class RealService extends Service {
|
|||||||
showToast(getApplication(), "stop Error");
|
showToast(getApplication(), "stop Error");
|
||||||
}
|
}
|
||||||
serviceIntent = null;
|
serviceIntent = null;
|
||||||
setAlarmTimer();
|
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
unregisterReceiver(mReceiver);
|
unregisterReceiver(mReceiver);
|
||||||
showToast(getApplication(), "stop Service");
|
showToast(getApplication(), "stop Service");
|
||||||
@ -266,6 +306,10 @@ public class RealService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
setNotification();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -288,16 +332,7 @@ public class RealService extends Service {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ public class RebootReceiver extends BroadcastReceiver {
|
|||||||
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, RealService.class);
|
||||||
context.startForegroundService(in);
|
context.startForegroundService(in);
|
||||||
} else {
|
} else {
|
||||||
Intent in = new Intent(context, RealService.class);
|
Intent in = new Intent(context, RealService.class);
|
||||||
|
@ -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>
|
@ -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