如何使用前台服务在类中创建的通知停止前台服务? Intent stopnotificationIntent = new Intent(this, HelloIntentService.class);
//Not sure which is the current action to set
stopnotificationIntent.setAction("ACTION.STOPFOREGROUND_ACTION");
PendingIntent pIntent = PendingIntent.getService(this, 0, stopnotificationInte
我正在尝试使屏幕调光的应用程序,将只有开/关功能,并从通知。如何使用.addAction实现待决意图的取消服务?
我可以在Service.class中通过stopSelf()停止服务,但不能从MainActivity中停止,但是如何在通知中实现它?
PendingIntent pi = PendingIntent.getService(MainActivity.this, 0, new Intent(MainActivity.this, MainService.class), 0);
final Notification notification = new
我有一个音乐控制通知,允许用户启动/停止音乐。我想要与Google Play Music应用程序通知完全相同的行为:当音乐播放时,服务在前台,通知不可取消,当音乐不播放时,服务不再在前台,通知可以删除。它可以正常工作,但是当我取消服务的前台时,通知会很快被删除,然后才会重新出现。
下面是我的代码,首先是如何构建通知:
NotificationCompat.Builder notifBuilder =
new android.support.v7.app.NotificationCompat.Builder(getApplicationContext())
我有一个Service在运行。在它的onStartCommand中,我使用startforeground来避免被系统杀死。
public int onStartCommand(Intent intent, int flags, int startId) {
if (ACTION_STOP_SERVICE.equals(intent.getAction())) {
Log.d(TAG,"called to cancel service");
manager.cancel(NOTIFCATION_ID);
stopSelf()
我有一个通知和一个“停止”按钮在上面。此按钮的PendingIntent引用BackgroundTaskService's内部类NotificationReceiver。但是当我点击“停止”按钮时,什么都不会发生。怎么啦?
NotificationsLab类:
class NotificationsLab{
/*...Some constructors, variables and other stuff here...*/
public Notification createNotification(UUID taskId){
Intent inte
在我们的安道尔广播接收机类,我们试图停止铃声,是从mainactivity.class发起的。我们使用mediaplayer.stop来停止铃声,这是成功的,但它崩溃了应用程序。我们使用了.stop ()、.pause ()、.release (),但不幸的是它们都没有工作。广播接收机的代码如下所示
Fire基类(摘要代码),其中媒体播放器初始化,挂起的广播意图按钮接收类被触发,在mediaplayer停止。
public class Firebase extends FirebaseMessagingService {
public static Ringtone r
我试过这些线索了:
我试过了,但没有成功
我想保持一个IntentService在后台运行,即使应用程序被杀死了。但如果我从最近的屏幕上删除我的应用程序,我的服务就会停止。我怎样才能避免这种情况?换句话说,即使我的应用程序从最近的应用程序中关闭了,我如何保持我的服务运行?
我的ForegroundService:
public class ForegroundService extends Service {
private static final String LOG_TAG = "ForegroundService";
public static boolean IS
我正在努力使我的Service在前台运行。一切都很好,但是在我杀死应用程序时,通知已经被清除了。
还有一点,它不适用于装有Android7.0的小米红米音符4。
样本代码:
final Intent notificationIntent = new Intent();
final PendingIntent pendingIntent = PendingIntent.getActivity(
this,
0,
notificationIntent,
0
);
fin
我刚开始使用匕首库。我已经创建了一个AppComponent,在这里我保存了一个房间数据库的单例实例。我有一个前台服务,当它的通知按钮被点击时,它需要写一些东西到房间数据库。正如您所知道的,前台服务通知对用户来说总是可见的,即使用户关闭了应用程序,我认为如果我的应用程序被杀死,AppComponent将不再可用。但是现在我可以访问它,并在单击服务通知按钮时获取数据库实例,即使我的应用程序已经从最近的应用程序中被清除。这是我的代码:
匕首应用程序模块:
@Module
class AppModule {
@Provides
@Singleton
fun database
我试图取消一个上传服务从我的进度通知使用‘取消’按钮。
但我做不到这件事。
通知创建为
//Intent class changes from first activity then to service when it's uploading.
Intent cancel = new Intent(intentClass, BaseUploadService.class);
PendingIntent cancelUploadIntent = PendingIntent.getBroadcast(intentClass, 0, cancel, PendingIntent.FLAG_C