我有一个小部件和4个按钮.这些按钮实际上是其他应用程序的快捷方式.我使用以下代码为每个按钮设置了onClick待定意图:
Intent i = context.getPackageManager().getLaunchIntentForPackage(s);                    
PendingIntent pi = PendingIntent.getActivity(context, 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(curIconId, pi);
通常它工作正常,但有时它不会做任何事情,在logcat中我看到一个SendIntentException,消息"无法发送待定意图".
如果我更新小部件(即再次设置挂起的意图),它再次正常工作.
关于它为什么有时会崩溃的任何想法?
谢谢
我有一个Android库,它有一个Service创建一个Notification.从我的理解Notification必须有一个contentIntent(PendingIntent)设置或运行时异常将被抛出.
问题是我希望用户能够按Service原样使用它,或者扩展它,以便他们可以PendingIntent在创建过程中通过回调设置自己Notification.但是,如果他们选择不这样做,我需要设置PendingIntent一些东西,以便没有例外.有没有办法创建一个PendingIntent只作为填充的假人?
以下是该createNotification方法的代码示例:
PendingIntent p;
if(getPendingIntentCallback != null) {
    p = getPendingIntentCallback.getPendingIntent();
}
else {
    p = ?;
}
notification.contentIntent = p;
android android-intent android-service android-notifications android-pendingintent
我正在尝试通过使用该setOnClickFillInIntent方法使我的ListView Widget中的listrows可单击,但每当我单击ListItem时都没有发生任何事情.以下是我的代码的一些关键部分:
Intent i = new Intent();
Bundle extras = new Bundle();
extras.putInt(Resource.WIDGET_PACKAGE, position);
i.putExtras(extras);
row.setOnClickFillInIntent(R.id.widget_layout_parent, i);
这是getView()我的ViewFactory 的结尾.Resource.WIDGET_PACKAGE包含我的包名称,就像任何其他键一样.位置int来自getView()参数.R.id.widget_layout_parent是所有列表项中的父布局.
这是我的WidgetProviders的结束 onUpdate()
Intent clickIntent = new Intent(context, ItemListActivity.class);
PendingIntent clickPI = PendingIntent.getActivity(context, 0,
        clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
widget.setPendingIntentTemplate(R.id.widget_layout_parent, clickPI);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i],
        R.id.widget_list_view);
有什么我想念的,或者你还有什么想知道的吗?
所有帮助表示赞赏!:)
android android-widget android-listview remoteview android-pendingintent
大家好我正在使用GCM推送通知向用户传递一些通知.我的问题是当我发送单个消息然后这个工作正常如果发送多个,然后最后一条消息显示给所有通知.帮我这个,我犯了错误......?
  private static void generateNotification(Context context, String message) {
  int icon = R.drawable.ic_launcher;
  long when = System.currentTimeMillis();
  NotificationManager notificationManager = (NotificationManager)
          context.getSystemService(Context.NOTIFICATION_SERVICE);
  Intent notificationIntent = new Intent(context, GCMMessageView.class);
  String[] messageArray = message.split("\\#");
  // param :: agentId, Name, Msg
  DatabaseHelper db = new DatabaseHelper(context);
  int notificationId = db.insertnotifications(messageArray[1], messageArray[0], messageArray[messageArray.length-1]);
  notificationIntent.putExtra("message", messageArray[messageArray.length-1]);
  // set intent so it does not start a new activity
  notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
  PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
  Notification notification = new NotificationCompat.Builder(context)
        .setContentText(messageArray[messageArray.length-1])
        .setContentTitle(context.getString(R.string.app_name))
        .setSmallIcon(icon)
        .setWhen(when)
        .setContentIntent(intent) …android push-notification android-pendingintent google-cloud-messaging
我已经实现了一个简单的GCM客户端,我在更新每次收到新通知时启动的Activity时遇到此问题.每次我发送带有一组参数的通知时,只有我为第一个通知发送的参数才会出现在UI中.当我尝试更改参数时,它们不会显示(再次显示相同的数据).
这是我的GcmIntentService类
public class GcmIntentService extends IntentService {
private static final String TAG = "GcmIntentService";
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public GcmIntentService() {
    super("GcmIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
                .equals(messageType)) {
            Log.d(TAG, "GCM error -> MESSAGE_TYPE_SEND_ERROR");
            sendNotification("Send error: " + extras.toString(), "", "",
                    "", "");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
                .equals(messageType)) {
            Log.d(TAG, "GCM error …notifications android android-pendingintent google-cloud-messaging
我正在尝试创建一个聊天应用程序,我的用户将收到通知.通知量如此之高,如果我为每个通知创建一个条目,那么它将填满所有地方,所以我想到应用BigTextView通知或堆栈通知.
我在下面写了一段代码:
NotificationManager notificationManager = (NotificationManager)
        this.getSystemService(Context.NOTIFICATION_SERVICE);
if(listMessage.size() <= 5)
listMessage.add(messagetype + ":" + msg);
else
{
     listMessage.remove(4);
     listMessage.add(messagetype + ":" + msg);
}
Intent notificationIntent = new Intent(this, GcmActivity.class);
notificationIntent.putExtra("title", messagetype);
notificationIntent.putExtra("message", msg);
PendingIntent intent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    NotificationCompat.Builder mBuilder;
        mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle("My MESSENGER")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText("MESSAGES"))
                        .setContentText(msg)
                        .setAutoCancel(true)
                        .setLights(Color.WHITE, 1000, 5000)
                        .setDefaults(Notification.DEFAULT_VIBRATE |
                                Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
                        .setContentIntent(intent);
        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle("MESSAGES");
        for(int j= 0;j < listMessage.size();j++)
        {
            inboxStyle.addLine(listMessage.get(j));
        } …我正在使用以下代码创建通知:
Intent intent = new Intent(this, GetStockQuote.class);
            intent.putExtra("abc", abcObject);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
            /* Build the notification */
            Notification notification = new Notification.Builder(this)
                                     .setContentTitle(abcObject.getCode())
                                     .setContentText(abcObject.getText())
                                     .setAutoCancel(false)
                                     .setSmallIcon(R.drawable.ic_launcher)
                                     .setContentIntent(pIntent).build();
 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(notificationID,notification);
            Log.i(TAG,"notification.notified");
如您所见,PendingIntent附加到通知的有效载荷.它是自定义类的对象.
现在我更新服务中的通知.我知道如果你必须更新通知(不创建新通知),你必须指定notificationID我正在做的相同.
这是用于更新上面创建的通知的服务中的代码:
Intent intent = new Intent(this, GetStockQuote.class);
                PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);   
 Notification notification=new Notification.Builder(this)
                                .setContentTitle(newTitle)
                                .setContentText(newBody)
                                .setSmallIcon(R.drawable.ic_launcher)
                                .setContentIntent(pIntent)
                                .build();
                /*Get instance of Notification Manager and show the notification*/
                        NotificationManager notificationManager = (NotificationManager) …我想让用户使用Google+登录.我在Google开发者控制台中创建了该项目,我获得了客户端ID,并在Android Studio中安装了Google Play服务.(我的运行设备有Android 4.4.2)当应用程序运行时我按下登录按钮会出现一个Toast消息:"Internal Error"
Logcat中的错误如下:
error ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{429ffe38: android.os.BinderProxy@429ffdd8}}
请注意,在用户按下按钮之前出现此错误,事实上,通过调试,我发现它来自此行代码:
Log.e(TAG, "error " + result.toString());
在方法中:
public void onConnectionFailed(ConnectionResult result) {
    if (!mGoogleIntentInProgress) {
        /* Store the ConnectionResult so that we can use it later when the user clicks on the Google+ login button */
        mGoogleConnectionResult = result;
        if (mGoogleLoginClicked) {
            /* The user has already clicked login so we attempt to resolve all errors until the user is signed in,
             * or they cancel. */
            resolveSignInError();
        } else …authentication android login google-plus android-pendingintent
我无法搞清楚Intent,PendingIntent 过滤器和标志的通知.
通知正在工作,并且正在按原样生成,但问题是只有最后创建的通知才能保留Bundle Data.
我希望所有通知都保留每个通知的Bundle Data,直到用户点击它们为止.
考虑一个应用程序片刻,当不同的用户向您发送消息时,会创建新通知,当您单击任何通知时,应用程序将启动并带您进入某个特定的活动.我想要相同的东西,但是当有多个通知时,最后一个通知会将Data保留在上一个通知中,而其中包含Bundle Data和Intent.
每次点击通知时,还有一个过滤器用于限制应用程序启动MainActivity的新实例.
每个通知的Notification_ID都不同.
public class AlarmSchedulingService extends IntentService {
private NotificationManager mNotificationManager;
public AlarmSchedulingService() {
    super("SchedulingService");
}
protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        sendNotification(extras.getInt(KEY_EXTRAS_NOTIFICATION_ID));
}
public void sendNotification(int NOTIFICATION_ID) {
mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(keyName, extraData); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent …我创建了PendingIntent这样的:
Intent intent = new Intent(context, AlarmReceiver.class);
intent.setAction("Foobar");
intent.putExtra(EXTRA_ALARM, alarm);
intent.putExtra(EXTRA_TRYTWO, tryTwo);
intent.putExtra(EXTRA_BEGAN_TIME, beganTime);
return PendingIntent.getBroadcast(
        context, (int) alarm.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT
);
该alarm变量是一个Parcelable.我这样安排PendingIntent:
PendingIntent alarmModifyPendingIntent = PendingIntent.getActivity(
        context, 0, editIntent, PendingIntent.FLAG_CANCEL_CURRENT
);
am.setAlarmClock(
    new AlarmManager.AlarmClockInfo(time, alarmModifyPendingIntent), pendingIntent
);
pendingIntent如上所示创建变量的位置.
的AlarmReceiver对象接收Intent在onReceive在正确的时间.但是,这Intent不包含我设置的额外内容.例如intent.getParcelableExtra(EXTRA_ALARM)返回null.
Android 7.0(API级别24)至少使用LG G5会出现此问题.
使用FLAG_CANCEL_CURRENT或FLAG_ONE_SHOT不工作.
android android-intent android-alarms android-pendingintent android-broadcast