[英]Turn On Notification Programatically in My Android app
我想以编程方式为我的Android应用程序打开Notification Access。
在某些Android设备中,默认情况下,我的应用程序的Notification Access是关闭的。 我想打开 ,并在应用程序本身动态关闭我的应用程序通知服务。
但是我对如何启用该服务一无所知。
请给我您的意见。
在活动中使用这种方法
public void sendNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity());
builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.journaldev.com/"));
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
builder.setContentIntent(pendingIntent);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setContentTitle("Notification title");
builder.setContentText("Your notification message.");
builder.setSubText("link for more info.");
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
}
public void cancelNotification() {
String ns = NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) getActivity().getApplicationContext().getSystemService(ns);
nMgr.cancel(1);
}
我认为这是不可能的。 android应用程序有一些限制,您只能通过root来传递。
您可以提示用户设置这些权限以使其正常运行。 在应用内设置这些听起来很恶意。 我高度怀疑这种事情是否可能。 (如果可以被应用覆盖,为什么Google首先要创建权限?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.