我的应用程序为用户交互设置了重复警报,它可能会更改使用Alarm Manager为广播设置的间隔时间.
额外的方式并不多.
在这种情况下更新或取消标志更好吗?
谢谢
如果我与我的应用程序进行交互(使用),我有一个警报可以正常工作,但是如果我将它设置为第二天并且不与我的应用程序进行交互则它不起作用.因此我怀疑这是因为我的应用程序进程没有运行那时候.
这就是我在做什么
Calendar calSet = Calendar.getInstance();
calSet.set(Calendar.HOUR_OF_DAY, selectedhour);
calSet.set(Calendar.MINUTE, selectedminute);
calSet.set(Calendar.YEAR, year);
calSet.set(Calendar.MONTH, monthOfYear);
calSet.set(Calendar.DATE, dayOfMonth);
alarm = new Intent(ActivityA.this, Service.class);
pendingIntent = PendingIntent.getService(getApplicationContext(), i++,alarm, 1);
alarmanager.set(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),pendingIntent);
Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于同一主题的帖子,并尝试了所有给定的解决方案而没有得到我想要的结果.程序应该从通知中添加额外的意图:
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, myActivity.class);
notificationIntent.putExtra("someData", data);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(ID, notification);
Run Code Online (Sandbox Code Playgroud)
问题是,当显示新通知时,添加到意图的附加内容与第一个通知中的附加内容相同.我在意图和未决意图中都有不同的标志,没有结果.我错了什么?如果我只是用一个按钮启动相同的活动(和相同的附加功能),一切都按预期工作.
我使用Alarm来从服务器获取数据.我想让用户选择启动和停止警报.这意味着我必须检查并查看是否已设置警报.我找到了一些代码告诉我警报是否已经设置:
Intent I = new Intent(getApplicationContext(),AlarmReceiver.class);
PendingIntent P = PendingIntent.getBroadcast(getApplicationContext(), 0, I, PendingIntent.FLAG_NO_CREATE);
found = (P!=null);
Run Code Online (Sandbox Code Playgroud)
如果警报已经设置我取消它但是如果它没有设置然后我设置它(像一个切换)
问题是这只能工作一次.第一次检查现有警报的上述代码将返回null,表示没有警报,但是在我取消警报后,一旦它返回指针,但警报未运行.
这是设置闹钟的代码
am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE);
Intent I = new Intent(getApplicationContext(),AlarmReceiver.class);
PendingIntent P = PendingIntent.getBroadcast(getApplicationContext(), 0, I, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, P);
Run Code Online (Sandbox Code Playgroud)
这是取消警报的代码:
am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE);
Intent I = new Intent(getApplicationContext(),AlarmReceiver.class);
PendingIntent P = PendingIntent.getBroadcast(getApplicationContext(), 0, I, PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(P);
Run Code Online (Sandbox Code Playgroud)
取消警报后,我是否要重置某些内容,以使其PendingIntent消失.
android alarm alarmmanager android-intent android-pendingintent
有一点问题一直困扰着我..
我已经设置了我的应用程序来接收来自Urban Airship的PUSH通知,并且一切正常,但是当我点击通知中心的通知时,没有任何反应.
当用户点击PUSH通知时,我希望我的应用程序打开 - 我该怎么做才能实现这一目标?
任何帮助总是非常感激.
谢谢
android push-notification urbanairship.com android-pendingintent
我想读取/访问/记录其他应用程序在通知栏上触发的通知.
我搜索Intents并PendingIntents不少,但无法得到解决.
在发出任何通知时,是否需要通知我的应用程序?
或者android系统是否提供了用户级应用程序读取通知的内容?
notifications android android-intent android-pendingintent accessibilityservice
我用a AlarmManager来启动服务.当我设置AlarmManager我使用PendingIntent并使用一个唯一的requestCode,它等于我的数据库中的id行.
PendingIntent pendingIntent = PendingIntent.getBroadcast(SettingsActivity.this,
lecture.getId(), myIntent, 0);
Run Code Online (Sandbox Code Playgroud)
如何在启动时在我的服务中检索该ID?我基本上只需要requestCode参数.我想使用该id从我的数据库中检索数据并在通知中显示它.我已经实现了所有的东西,我只需要requestCode.有可能得到它吗?
谢谢
notifications android broadcastreceiver alarmmanager android-pendingintent
在下面发布的代码中,我创建了一个自定义布局的通知.通知的布局包含三个操作按钮.
我现在的问题是,我无法引用代码中的任何按钮,以便我可以根据单击的操作按钮导航到另一个活动.我想要做的Action button 1
是点击何时Activity 1显示,何时Action button 2单击然后Activity 2出现等等.
请告诉我如何在通知的自定义布局中引用视图?
代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Using RemoteViews to bind custom layouts into Notification
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_notification);
String notification_title = "Notification_Title";
String notification_text = "Notification_Text";
// Open NotificationView Class on Notification Click
Intent intent = new Intent(this, NotificationReply.class);
// Send data to NotificationView Class
intent.putExtra("title", notification_title);
intent.putExtra("text", notification_text);
// …Run Code Online (Sandbox Code Playgroud) java android android-notifications remoteview android-pendingintent
我正在我的应用程序上创建一个PDF文件,并将其写入外部存储"下载"目录.现在,当我通过我的应用程序通过intent action.VIEW使用FileProvider uri打开它时,Google PDF Viewer显示一个空白屏幕,Adobe Acrobat甚至无法打开该文件.这是我编写文件然后尝试显示它的代码.请注意,我正在发送本地通知并尝试通过通知打开文件.
try {
File mypath=new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),mParam1.getEmlak_id()+".pdf");
document.writeTo(new FileOutputStream(mypath));
document.close();
NotificationManager notificationManager = (NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE);
File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),mParam1.getEmlak_id()+".pdf");
Uri pdfUri = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".com.onur.emlakdosyasi.provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(pdfUri, "application/pdf");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//use the flag FLAG_UPDATE_CURRENT to override any notification already there
PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(getContext())
.setContentTitle("title")
.setContentText("content")
.setSmallIcon(R.drawable.pdficon)
.setContentIntent(contentIntent)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH)
.build();
notificationManager.notify(10, notification);
} catch (FileNotFoundException e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) pdf android android-intent android-pendingintent android-fileprovider
最近遇到了一个问题,即添加地理围栏将随机失败,并显示ApiException,状态码为13(定义为“错误”),未提供其他详细信息。
通常,错误代码特定于地理围栏,但这似乎是一般性故障。有谁知道为什么GeofencingClient返回状态码13?我一直找不到任何有相同问题的人。
这似乎影响了以前无法正常运行的旧版应用。
我已经再次检查了经度/纬度是有效的坐标,并且相同的数据有时可以正常工作。我尝试使用不同的API密钥进行初始化,以防地图/位置服务出现问题,但这没什么区别。
我也试着从改变
GeofencingClient(context)到LocationServices.getGeofencingClient(context)没有变化。
我试过升级库版本,没有区别。
典型的清单设置,其中定义了播放服务版本和API密钥;
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/maps_api_key"/>
<service android:name=".GeofenceTransitionsIntentService"/>
Run Code Online (Sandbox Code Playgroud)
地理围栏已添加到此处,意图服务从未获得任何结果
private val geofencingClient = GeofencingClient(context)
private val geofencePendingIntent =
PendingIntent.getService(context, 0, Intent(context, GeofenceTransitionsIntentService::class.java), PendingIntent.FLAG_UPDATE_CURRENT)
fun setGeofence(latitude: Double, longitude: Double, radius: Float, geofenceId: String) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
val geofenceList = listOf(buildGeofence(latitude, longitude, radius, geofenceId))
geofencingClient.addGeofences(getGeofencingRequest(geofenceList), geofencePendingIntent)?.run {
addOnFailureListener {
// Failed to add geofences
geofenceErrorListener?.invoke("Failed to add Geofence: ${it.message}")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
直到最近,这才成为问题,现在几乎100%的时间都在发生。
com.google.android.gms.common.api.ApiException: 13:
Run Code Online (Sandbox Code Playgroud)
编辑:从PlayServices版本17.7.85开始(在我的设备上),该问题似乎已在Google端得到解决
android android-pendingintent google-play-services android-geofence