nsandersen
nsandersen

Reputation: 976

Why does my Intent open App Info in Settings for my app, rather than the Activity class I pass to it?

I have an Activity which starts a foreground Service with a Notification. If relevant, the Service may also be set to start on boot, ie. I expect it to be able to start without the Activity also.

I want it to be so that if I tap the Notification, then I go to my Activity where I can stop the service, change settings etc.

I supply an Intent with the Activity class to a PendingIntent for a Notification for the foreground Service.

If I tap the Notification it opens the App Info in system settings for my app (where you can Force Stop, Uninstall etc.), not the Activity itself. How can I make it do the latter?

This is the code that creates the Notification when the service starts:

@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);
...

I have also tried creating the Intent with

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

with the same result. I wonder if the problem has to do with Contexts?

EDIT: I could not change the text on the notification either.

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

I should also mention this is the LineageOS Android flavor. Thank you.

Upvotes: 7

Views: 1887

Answers (1)

nsandersen
nsandersen

Reputation: 976

This works if I set an icon, which I hadn't made yet, due to artistic deficiencies. Unlike this question it is not necessary to set the icon first in this case.

It is as if it ignores the notification passed to the startForeground method and supplies a default one unless it includes an icon.

Once I added that via setSmallIcon(R.drawable...) all worked as expected.

Upvotes: 11

Related Questions