简体   繁体   中英

How can I launch wifi settings from a PendingIntent?

I'm trying to launch settings from a foreground service but getActivity() and getService() do nothing. Settings is never launched. Edit: here is how I'm setting the pending intent. The foreground service shows a plain notification with a line of clickable text

notificationBuilder.setOngoing(true) 
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS));
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
notificationBuilder.addAction([mydrawable], "openSettings", pIntent);

This worked for me when I wanted to launch wifi settings on notification clicked.

val notificationBuilder = NotificationCompat.Builder(context, channelId).apply{setSmallIcon(R.drawable.icon)---<more code here>..
  val intent = Intent(Settings.ACTION_WIFI_SETTINGS)
        val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
        setContentIntent(pendingIntent)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM