将挂起的意图上的标志设置为0时会发生什么?它是不是没有标志或是否默认为其他标志之一?
我有一个基本的问题,我不认为附加任何代码片段可能会有所帮助.当我们在应用程序位于前面时按下主页按钮时,我们转到主页,应用程序失去了焦点.
现在,我的应用程序必须在状态栏中有通知图标.就像在我的应用程序中一样,有可能显示2-3个活动(在对话视图中一个在另一个上面).在某些情况下,当我按状态栏中的通知图标时,我不确定如何恢复这种状态.
但是,当我按下主页按钮然后按主屏幕中的应用程序图标时,我得到了所有内容.
那么,有什么方法可以用通知栏图标做同样的事情.
int id = 0;
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.notification_on_the_move_gps_title))
.setContentText(context.getString(R.string.notification_on_the_move_text));
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.notification_on_the_move_gps_big_text)));
Intent mainIntent = new Intent(context, MainActivity.class);
Intent turnOffIntent = new Intent(context, MainActivity.class);
turnOffIntent.putExtra(MainApp.KEY_TURN_OFF_NOTIFICATION_ID, id);
TaskStackBuilder mainBuilder = TaskStackBuilder.create(context);
mainBuilder.addParentStack(MainActivity.class);
mainBuilder.addNextIntent(mainIntent);
PendingIntent mainPendingIntent = mainBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(mainPendingIntent);
TaskStackBuilder turnOffBuilder = TaskStackBuilder.create(context);
turnOffBuilder.addParentStack(MainActivity.class);
turnOffBuilder.addNextIntent(turnOffIntent);
PendingIntent turnOffPendingIntent = turnOffBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder
.setSmallIcon(R.drawable.ic_stat_notification)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
.setAutoCancel(true)
.setLights(Color.BLUE, 500, 500)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.addAction(R.drawable.ic_stat_notification, "Open", mainPendingIntent)
.addAction(R.drawable.ic_stat_notification_off, "Turn off", turnOffPendingIntent);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(id, builder.build());
Run Code Online (Sandbox Code Playgroud)
单击未展开或扩展的通知正文或打开操作按钮始终使用(KEY_TURN_OFF_NOTIFICATION_ID)额外传递意图.
我试过放弃TaskStackBuilder并PendingIntent …
我有一个应用程序,提醒人们完成他们的任务.所以有一个PendingIntent,现在用户可以在他想要的时候删除警报.在这段代码中,只有一个PendingIntent用于多个用户警报,因此我对取消意图附加功能的特定警报感到困惑"pill".其余警报不应取消.我对这个问题一无所知.希望我很清楚.谢谢
Intent intent = new Intent(this, AlarmNotifyReceiver.class);
intent.putExtra("Name_pill", "pill");
sender = PendingIntent.getBroadcast(this,
DatabaseConstants.NOTIFICATION_ID + 1, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), sender);
updateTheFlag(pillName[(pillName.length-1)]);
Run Code Online (Sandbox Code Playgroud) 我正在实现一个响应RecognizerIntent的活动.除此之外,此活动必须处理两个指定待处理意图的附加附加内容及其附加内容:
EXTRA_RESULTS_PENDINGINTENTEXTRA_RESULTS_PENDINGINTENT_BUNDLE解释文档:
如果您使用EXTRA_RESULTS_PENDINGINTENT提供a PendingIntent,则结果将添加到其包中,PendingIntent并将结果发送到其目标.
如果您使用EXTRA_RESULTS_PENDINGINTENT提供转发意图,您还可以使用EXTRA_RESULTS_PENDINGINTENT_BUNDLE为最终意图提供额外的额外内容.搜索结果将添加到此捆绑包中,组合捆绑包将发送到目标.
我一直在寻找可以证明以下内容的示例代码.
PendingIntent从捆绑中提取a的最佳方法是什么?
我应该这样做:
(PendingIntent)
extras.getParcelable(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT)
Run Code Online (Sandbox Code Playgroud)
如何在一组现有的附加内容中添加额外内容PendingIntent?
如何启动修改PendingIntent?
我的Widget启动服务,服务更新3个LinearLayouts列表.
我想在每个LinearLayout上设置一个具有不同Extra的SetOnClickPeningIntent
但是,当我启动小部件并想要点击LinearLayouts时,只有最后一个是onclickable = /我不知道什么是错的.希望您能够帮助我.
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.widget_layout);
for (int widgetId : appWidgetIds) {
int[] lls = { R.id.ll_con_1, R.id.ll_con_2, R.id.ll_con_3 };
for (int i = 0; i < jray.length(); i++) {
try {
JSONObject o = jray.getJSONObject(i);
//Onclick
if(i == 0)
{
Intent msg_intent = new Intent(getApplicationContext(), MSGsOpenMsg.class);
msg_intent.putExtra("messageid", o.getString("id"));
PendingIntent msg_pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, msg_intent, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(R.id.ll_con_1, msg_pendingIntent);
}
else if(i == 1)
{
Intent msg_intent1 = new Intent(getApplicationContext(), MSGsOpenMsg.class);
msg_intent1.putExtra("messageid", o.getString("id"));
PendingIntent msg1_pendingIntent …Run Code Online (Sandbox Code Playgroud) 我试图与一个按钮一个简单的小工具,开始Service用OnClickPendingIntent().我可以开始很好,但我无法找到一种方法来阻止它(我知道我可以用一个BroadcastReceiver或类似的东西,但我想避免硬编码).
这是我的代码:
Intent intent = new Intent(context, myService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);
if (!ismyserviceup(context)) {
views.setOnClickPendingIntent(R.id.my_button, pendingIntent);
} else {
// i need to stop it!!!!
}
Run Code Online (Sandbox Code Playgroud) android android-widget android-service android-pendingintent
我有一个widget类(扩展AppWidgetProvider),它在widget的布局中只有一个视图(ImageView).当用户点击小部件时,它会更新并启动一个没有问题的活动.小部件更新后,小部件每30分钟更新一次并启动活动.我的问题是:如何将窗口小部件配置为仅在自动更新时更新自身(而不是通过用户单击)?
这是我的代码:
public class Widget extends AppWidgetProvider {
private static final String ACTION_UPDATE = AppWidgetManager.ACTION_APPWIDGET_UPDATE;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
ComponentName cn = new ComponentName(context, Widget.class);
appWidgetManager.updateAppWidget(cn, remoteView(context));
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equalsIgnoreCase(ACTION_UPDATE)) {
ComponentName cn = new ComponentName(context, Widget.class);
AppWidgetManager.getInstance(context).updateAppWidget(cn,
remoteView(context));
Intent launch = new Intent(context, Main.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, launch, 0);
try {
pi.send();
} catch (CanceledException e) {
e.printStackTrace();
}
}
} …Run Code Online (Sandbox Code Playgroud) 面向 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 可变时才使用 FLAG_MUTABLE
我无法更新 android studio 项目编码中的挂起意图标志
这是AlarmPingSender.java中发生错误的地方
public void start()
{
String action = MqttServiceConstants.PING_SENDER
+ comms.getClient().getClientId();
Log.d(TAG, "Register alarmreceiver to MqttService"+ action);
service.registerReceiver(alarmReceiver, new IntentFilter(action));
pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
action), PendingIntent.FLAG_UPDATE_CURRENT);
schedule(comms.getKeepAlive());
hasStarted = true;
}
Run Code Online (Sandbox Code Playgroud)