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

标签 android android-intent android-pendingintent android-8.1-oreo

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

我希望它是这样的,如果我点击通知,然后我会转到我的 Activity ,在那里我可以停止服务、更改设置等。

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

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

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

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

同样的结果。我想知道问题是否与上下文有关?

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

日志:

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 风格。谢谢。

最佳答案

如果我设置了一个我还没有制作的图标,这是可行的,因为艺术缺陷。 Unlike this question在这种情况下不需要先设置图标。

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

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

关于android - 为什么我的 Intent 在我的应用程序的设置中打开应用程序信息,而不是我传递给它的 Activity 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55634562/

相关文章:

java - Android将字节数组转换为文件并将文件保存在SD卡中

java - AlarmManager setInexactRepeating、setWindow、setRepeating 方法在一周内从循环内调用时不会触发警报

android - 我的 onReceive 响应哪个请求?

java.lang.IllegalArgumentException : column '_id' does not exist with Ormlite cursor 异常

android - 从android中具有多个id的列表项中获取一个id值

android - 使用图像启动 ACTION_EDIT 并返回图像的教程/引用

Android-当用户点击通知时打开浏览器

Android 如何以编程方式创建 View

Android WebView 在 WebView 中单击打开不是默认浏览器

java - 收到推送通知和未调用 CGM Intent 服务时应用程序崩溃