相关疑难解决方法(0)

如何查看在Android上运行的应用?

我是Android开发人员,我想if在我的应用程序中编写一个语句.在此声明中,我想检查默认浏览器(Android OS中的浏览器)是否正在运行.我该如何以编程方式执行此操作?

java browser android if-statement

65
推荐指数
2
解决办法
7万
查看次数

Android如何在屏幕上显示通知

我一直致力于推送通知,我能够实现它并在状态栏上显示它,我面临的问题是我想显示它,即使手机是锁定的,在它所说的锁定屏幕下("拖动解锁"),我已经看过这样的通知,但无法找到任何示例.

示例: 就像您收到未接来电一样,它会在屏幕上的锁定按钮下显示.

码:

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon_launcher;
CharSequence tickerText = "MyApplication";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;;
CharSequence contentTitle = this.title;
CharSequence contentText = this.message;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTICE_ID, notification);
Run Code Online (Sandbox Code Playgroud)

notifications android lockscreen

28
推荐指数
3
解决办法
8万
查看次数

如何在android中创建自定义通知布局?

如何在android中使用通知风格或需要进行自定义布局时在frist时间显示通知中的完整内容?

android push-notification

20
推荐指数
2
解决办法
4万
查看次数

如何在Android应用程序(活动或服务)被杀死时删除所有通知?

我有一个应用程序,其中包含在后台运行的活动和意图服务.

还有一个通知,显示进度条与后台进程的进度(它从服务器下载了大量文件).

该活动具有下载进度(用户在下载这些资产之前无法有意义地使用该应用程序).关闭此活动时,将显示带有进度条的通知.

我的问题:当应用程序被"任务管理器"(可通过​​android 4.0上的右键,具有两个矩形的那个)访问时,通知仍然存在.但它基本上是一个僵尸,因为用于更新它的服务已经死了.

换一种方式:当我的应用程序被杀死时,如何删除(或所有)通知?

service notifications android

13
推荐指数
1
解决办法
1万
查看次数

Forgeround 服务在几分钟后停止或锁定电话

我尝试创建每 20 秒发送一条消息的前台服务,但此服务在几分钟后停止或锁定电话。我在 android 8 (O) 中测试了这个服务。我的代码是:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
  input = intent.getStringExtra("inputExtra");

  new Thread(new Runnable() {
    public void run() {
      while (progressStatus < 10000000) {
        progressStatus += 1;           
        handler.post(new Runnable() {
          @SuppressLint("MissingPermission")
          public void run() {
            Intent notificationIntent = new Intent(ExampleService.this, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(ExampleService.this,
              0, notificationIntent, 0);
            String mmm = CHANNEL_ID;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
              notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
              id = "id_product";
              // The user-visible name of the channel. …
Run Code Online (Sandbox Code Playgroud)

android background-foreground foregroundnotification foreground-service

5
推荐指数
1
解决办法
2388
查看次数

后台服务在奥利奥中不起作用

如果我也杀死了应用程序实例,我想在后台运行我的应用程序。但是在我杀死我的应用程序后,该服务也停止工作。这是我的代码,请任何人帮助我解决我的问题。

我按照此链接在后台运行,但如果我删除实例,它就不起作用。如果实例也被删除,请任何人告诉我如何运行后台服务?

这是我的主要活动

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ctx = this;
    setContentView(R.layout.activity_main);
    Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(MainActivity.this, ALARM_REQUEST_CODE, alarmIntent, 0);
    mSensorService = new SensorService(getCtx());
    mServiceIntent = new Intent(getCtx(), mSensorService.getClass());
    if (!isMyServiceRunning(mSensorService.getClass())) {
        startService(mServiceIntent);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的服务类

   public class SensorService extends Service{

public int counter=0;
public SensorService(Context applicationContext) {
    super();
    Log.i("HERE", "here I am!");
}

public SensorService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    startTimer();
    return START_STICKY; …
Run Code Online (Sandbox Code Playgroud)

android background android-8.1-oreo

1
推荐指数
1
解决办法
1万
查看次数