为什么我的Intent在我的应用的设置中打开应用信息,而不是我传递给它的Activity类?

问题描述 投票:0回答:1

我有一个Activity,它启动带有通知的前台服务。如果相关,也可以将服务设置为在启动时启动,即。我希望它能够在没有活动的情况下开始。

我希望它是如此,如果我点击通知,然后我去我的活动,我可以停止服务,更改设置等。

我将一个带有Activity类的Intent提供给PendingIntent,用于前台服务的通知。

如果我点击通知,它会在我的应用程序的系统设置中打开应用程序信息(您可以强制停止,卸载等),而不是活动本身。我怎样才能做到后者呢?

这是在服务启动时创建通知的代码:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Context con = getApplicationContext();
    String chanID = "com.blah.MyApp";
    NotificationChannel chan = new NotificationChannel(chanID, getString(R.string.app_name), NotificationManager.IMPORTANCE_NONE);
    NotificationManager manager = (NotificationManager) con.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.createNotificationChannel(chan);

    PendingIntent penitent = PendingIntent.getActivity(con, 1, new Intent(getBaseContext(), MyApp.class), 0);
    Notification notif = new NotificationCompat.Builder(con, chanID).setContentIntent(penitent).build();

    startForeground(1, notif);
...

我也试过创建Intent

 Intent.makeMainActivity(new ComponentName("com.blah", "MyApp"));

结果相同。我想知道问题是否与Contexts有关?

编辑:我也无法更改通知上的文字。

logcat的:

2019-04-12 09:50:56.062 1395-6289/? I/ActivityManager: START u0 {act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.blah cmp=com.android.settings/.applications.InstalledAppDetails} from uid 1000
2019-04-12 09:50:56.067 1395-6289/? W/ActivityManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.blah cmp=com.android.settings/.applications.InstalledAppDetails }
2019-04-12 09:50:56.072 30945-30957/com.blah I/zygote64: Do partial code cache collection, code=61KB, data=57KB
2019-04-12 09:50:56.076 30945-30957/com.blah I/zygote64: After code cache collection, code=61KB, data=57KB
2019-04-12 09:50:56.079 30945-30957/com.blah I/zygote64: Increasing code cache capacity to 256KB
2019-04-12 09:50:56.102 1395-25718/? E/ActivityManager: applyOptionsLocked: Unknown animationType=0
2019-04-12 09:50:56.142 31157-31157/? I/zygote64: Deoptimizing void android.widget.LinearLayout.<init>(android.content.Context, android.util.AttributeSet, int, int) due to JIT inline cache
2019-04-12 09:50:56.204 31157-31157/? I/zygote64: Deoptimizing void android.widget.RelativeLayout$LayoutParams.<init>(android.content.Context, android.util.AttributeSet) due to JIT inline cache
2019-04-12 09:50:56.285 31157-31157/? W/Settings: Unable to find info for package: null
2019-04-12 09:50:56.339 31157-31189/? W/TileUtils: Found com.android.settings.backup.BackupSettingsActivity for intent Intent { act=com.android.settings.action.SETTINGS pkg=com.android.settings } missing metadata com.android.settings.category
2019-04-12 09:50:56.350 31157-31189/? W/TileUtils: Found org.lineageos.lineageparts.trust.TrustPreferences for intent Intent { act=org.lineageos.lineageparts.action.SETTINGS pkg=org.lineageos.lineageparts } missing metadata 
2019-04-12 09:50:56.362 31157-31157/? W/InstalledAppDetails: App is not explicitly stopped
2019-04-12 09:50:56.367 31157-31157/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:1556 android.content.ContextWrapper.bindService:684 android.content.pm.permission.RuntimePermissionPresenter$RemoteService.processMessage:171 android.content.pm.permission.RuntimePermissionPresenter.getAppPermissions:118 com.android.settingslib.applications.PermissionsSummaryHelper.getPermissionSummary:34 
2019-04-12 09:50:56.372 31157-31157/? D/AppUtils: Have 0 number of activities in preferred list
2019-04-12 09:50:56.397 1395-1431/? I/WifiService: requestActivityInfo uid=1000
2019-04-12 09:50:56.397 1395-1431/? I/WifiService: reportActivityInfo uid=1000
2019-04-12 09:50:56.397 1395-1431/? I/WifiService: getSupportedFeatures uid=1000
2019-04-12 09:50:56.410 1395-1431/? E/BatteryExternalStatsWorker: no controller energy info supplied for wifi
2019-04-12 09:50:56.410 1395-1431/? E/BatteryExternalStatsWorker: no controller energy info supplied for bluetooth
2019-04-12 09:50:56.500 31157-31189/? D/Settings: No enabled state changed, skipping updateCategory call
2019-04-12 09:50:56.528 31157-31157/? W/InstalledAppDetails: App is not explicitly stopped
2019-04-12 09:50:56.537 31157-31157/? D/AppUtils: Have 0 number of activities in preferred list
2019-04-12 09:50:56.555 31157-31157/? W/InstalledAppDetails: App is not explicitly stopped
2019-04-12 09:50:56.566 31157-31157/? D/AppUtils: Have 0 number of activities in preferred list
2019-04-12 09:50:56.582 31157-31189/? W/ProcStatsManager: No process com.google.android.configupdater/10017 for service com.google.android.configupdater.MainJobService
2019-04-12 09:50:56.582 31157-31189/? W/ProcStatsManager: No process com.android.defcontainer/10026 for service com.android.defcontainer.DefaultContainerService
2019-04-12 09:50:56.582 31157-31189/? W/ProcStatsManager: No process com.android.vending:instant_app_installer/10029 for service com.google.android.finsky.instantapps.InstantAppHygieneService
2019-04-12 09:50:56.582 31157-31189/? W/ProcStatsManager: No process com.android.vending:instant_app_installer/10029 for service com.google.android.finsky.instantapps.PhenotypeUpdateService
2019-04-12 09:50:56.583 31157-31189/? W/ProcStatsManager: No process com.android.vending:instant_app_installer/10029 for service com.google.android.finsky.instantapps.metrics.LogFlushJob
2019-04-12 09:50:56.583 31157-31189/? W/ProcStatsManager: No process com.firebase.jobdispatcher.GooglePlayReceiver
2019-04-12 09:50:56.583 31157-31189/? W/ProcStatsManager: No process com.android.cellbroadcastreceiver/10015 for service com.android.cellbroadcastreceiver.CellBroadcastConfigService
2019-04-12 09:50:56.605 31157-31189/? W/ProcStatsManager: No process com.google.android.gms.ui/10010 for service com.google.android.gms.chimera.UiIntentOperationService
2019-04-12 09:50:56.605 31157-31189/? W/ProcStatsManager: No process com.google.android.gms.learning/10010 for service com.google.android.gms.learning.training.background.TrainingGcmTaskService
2019-04-12 09:50:56.605 31157-31189/? W/ProcStatsManager: No process com.google.android.partnersetup/10016 for service com.google.android.partnersetup.InstalledAppJobService
2019-04-12 09:50:56.605 31157-31189/? W/ProcStatsManager: No process com.google.android.apps.translate/10102 for service com.google.android.libraries.internal.growth.growthkit.internal.jobs.impl.GrowthKitJobService
2019-04-12 09:50:56.698 1395-1435/? I/ActivityManager: Displayed com.android.settings/.applications.InstalledAppDetails: +565ms

我还要提一下这是LineageOS Android风味。谢谢。

android android-intent android-pendingintent android-8.1-oreo
1个回答
0
投票

如果我设置一个我尚未制作的图标,由于艺术上的缺陷,这是有效的。 Unlike this question在这种情况下没有必要先设置图标。

就好像它忽略了传递给startForeground方法的通知并提供了一个默认的通知,除非它包含一个图标。

一旦我通过setSmallIcon(R.drawable ...)添加,所有工作都按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.