标签: android-notifications

android-如何获取解析推送通知发送的json数据

我正在使用parse.com发送推送通知.它工作正常.

我想通过parse.com发送这个json数据:

{"channel":"game","data":{ "alert":"Red Sox win 7-0!"}}
Run Code Online (Sandbox Code Playgroud)

这是我的主要动力:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ParseAnalytics.trackAppOpened(getIntent());

    // inform the Parse Cloud that it is ready for notifications
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseInstallation.getCurrentInstallation().saveInBackground();

}
Run Code Online (Sandbox Code Playgroud)

1-如何获取此json数据?

2-我发送了json数据,如何禁用通知?当应用程序获得json时,会显示通知并说"解析推送通知".如果我发送json数据,如何禁用此通知?

android json android-notifications

0
推荐指数
1
解决办法
1952
查看次数

Android 通知:使用多个 setOnClickPendingIntent 时的错误

我有一个奇怪的错误。

我收到了一个带有 3 个按钮(后退、下一步、播放/暂停)的通知。我想在启动服务的这三个按钮中的每一个上设置不同的 pendingIntent。这是我的代码:

    Intent playPauseIntent = new Intent(MyApp.mainActivity, NotificationService.class);
    playPauseIntent.putExtra("do_action", "play");
    contentView.setOnClickPendingIntent(R.id.notifPlayPauseImageView, PendingIntent.getService(MyApp.mainActivity, 0, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT));            

    Intent nextRadioIntent = new Intent(MyApp.mainActivity, NotificationService.class);
    nextRadioIntent.putExtra("do_action", "next");
    contentView.setOnClickPendingIntent(R.id.notifNextImageView, PendingIntent.getService(MyApp.mainActivity, 0, nextRadioIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    Intent previousRadioIntent = new Intent(MyApp.mainActivity, NotificationService.class);
    previousRadioIntent.putExtra("do_action", "previous");
    contentView.setOnClickPendingIntent(R.id.notifPreviousImageView, PendingIntent.getService(MyApp.mainActivity, 0, previousRadioIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    notification.contentView = contentView;
    mNotificationManager.notify(1, notification); 
Run Code Online (Sandbox Code Playgroud)

然后,在我的服务中,我将“do_action”的意图和值定义为额外的:

@Override
public int onStartCommand(Intent intent,  int flags, int startId) { 

   if(intent != null && intent.getExtras() != null)
   {
      String action = (String) intent.getExtras().get("do_action"); // BUG HERE ! I always get …
Run Code Online (Sandbox Code Playgroud)

java android android-intent android-notifications android-pendingintent

0
推荐指数
1
解决办法
213
查看次数

Android 通知自定义布局 XML imageview 未显示

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="96dp"
    android:gravity="center"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:paddingStart="24dp"
        android:paddingBottom="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/pushIcon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                app:srcCompat="@drawable/push_icon" />

            <TextView
                android:id="@+id/textView23"
                style="@style/TextAppearance.Compat.Notification.Info.Media"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="6dp"
                android:text="YOLOL"
                android:textColor="@color/browser_actions_title_color" />
        </LinearLayout>

        <TextView
            android:id="@+id/text_view_collapsed_1"
            style="@style/TextAppearance.Compat.Notification.Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:text="New Message!"
            android:textColor="@color/colorPrimary" />

        <TextView
            android:id="@+id/text_view_collapsed_2"
            style="@style/TextAppearance.Compat.Notification.Info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Expand to show!" />
    </LinearLayout>

    <ImageView
        android:id="@+id/notifPreviewImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        app:srcCompat="@drawable/bb" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ImageViewpushIcon占据了位置但不可见,知道为什么吗?

android android-layout android-notifications

0
推荐指数
1
解决办法
529
查看次数

Android - 如何创建带有操作的通知

我正在创建这样的通知。

Notification.Builder builder = new Notification.Builder(context);
        builder.setContentTitle(notifyMessage1)
                .setContentText(notifyMessage2)
                .setSmallIcon(R.mipmap.ic_launcher);

Notification notification = builder.build();
Run Code Online (Sandbox Code Playgroud)

我想在我的通知中添加一个操作

builder.addAction();
Run Code Online (Sandbox Code Playgroud)

实现addAction(icon, title, pendingIntent);已弃用

我的目标是创建一个没有图标的通知操作,我该如何实现?

android android-notifications

-2
推荐指数
2
解决办法
9942
查看次数