标签: android-remoteview

Android Remoteviews用于扩展通知

Jelly Bean中引入的扩展通知允许添加操作.这些操作显示为一行中的按钮.如果我想用我自己的自定义视图修改它,我会考虑使用remoteview.

扩展通知是否允许远程视图?我只能在扩展通知存在之前找到在简单通知中使用的远程视图的示例.

android notificationmanager android-notifications android-4.2-jelly-bean android-remoteview

5
推荐指数
1
解决办法
6314
查看次数

使用RemoteViews的通知不起作用

我正在尝试发出自定义通知(具有播放暂停,下一个和上一个按钮).但这似乎不起作用:

  • 我想要的:从我的活动中发出带有播放暂停,下一个和上一个按钮的自定义通知.此活动有一个有效的MediaPlayer

  • 问题是:通知根本没有发出.

  • 我做了什么:MediaPlayer完成后,从我的Activity onCreate()调用以下代码:

任何帮助都非常感谢.谢谢 !!

    private void sendNotification() {

        Log.v(LOGTAG, "Inside sendNotification");

        // Creating RemoteView and inflating it with a custom XML layout file    
        RemoteViews notificationViews = new RemoteViews(getPackageName(), R.layout.notification);

        Updating some fields in the layout file
        notificationViews.setTextViewText(R.id.songNameTextViewNotify, trackInfo.getTrack());
        notificationViews.setImageViewUri(R.id.songImageViewNotify, Uri.parse(trackInfo.getAlbumImageURL()));

        // Notification builder    
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).
                setContent(notificationViews);

                // Pending intent to call my class
                // The intent will be caught in the onNewIntent() method
        Intent intent = new Intent(this, MusicPlayer.class);
        PendingIntent pendingIntent …
Run Code Online (Sandbox Code Playgroud)

notifications android android-mediaplayer android-remoteview

5
推荐指数
0
解决办法
1556
查看次数

远程通知显示空白

当我在没有远程视图的情况下创建通知时,它工作正常,但是当我尝试使用远程视图时,通知显示空白屏幕.这是我的通知代码: - /

RemoteViews remoteViews = new RemoteViews(getPackageName(),
           R.layout.widget);
    remoteViews.setTextViewText(R.id.date,result);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
         this).setSmallIcon(R.drawable.common_signin_btn_icon_dark).setContent(remoteViews);

    Intent resultIntent = new Intent(this, NotificationDatabase.class);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    this,
                    0,
                    resultIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(1, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

这是我的widget.xml: - /

 <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/request"
    android:text="NEW APPOINTMENT REQUEST"
    android:textSize="27dp"
    android:layout_marginTop="81dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Accept"
    android:id="@+id/accept"
    android:layout_marginLeft="15dp"
    android:layout_below="@+id/request"
    android:layout_alignParentStart="true"
    android:layout_marginTop="61dp" …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-remoteview

5
推荐指数
0
解决办法
328
查看次数

Remoteview中的ViewFlipper showNext()和showPrevious()无法正常工作

我正在一个项目中工作,我需要在Notification栏的Remoteview中使用ViewFlipper视图.目前我正面临着showNext()和showPreview()的问题.但不幸的是,当我调用按钮时,不会调用showNext()和showPreview().我也发布了我的代码供您参考.如果我的问题不明确,请帮助我在哪里犯错误并纠正我.

 private Notification setCustomViewNotification() {

        // Creates an explicit intent for an ResultActivity to receive.
        Intent resultIntent = new Intent(this, ResultActivity.class);

        // This ensures that the back button follows the recommended convention for the back key.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(ResultActivity.class);

        // Adds the Intent that starts the Activity to the top of the stack.
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Create remote view and set …
Run Code Online (Sandbox Code Playgroud)

notifications android viewflipper android-appwidget android-remoteview

5
推荐指数
1
解决办法
673
查看次数

RemoteViewsService 未从通知中调用

我想在通知中显示 GridView,我正在使用 RemoteViews 来显示自定义布局。我的代码如下所示:

public class MainActivity extends AppCompatActivity {

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

        showNotification();
    }

    private void showNotification(){

        RemoteViews rw = new RemoteViews(this.getPackageName(), R.layout.notification_layout);
        rw.setRemoteAdapter(R.id.grid_view, new Intent(this, AppService.class));
        rw.setImageViewResource(R.id.image, R.mipmap.ic_launcher);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Custom View")
                .setContent(rw);    
        ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(1, builder.build());    

        //startService(new Intent(this, AppService.class));

    }

}
Run Code Online (Sandbox Code Playgroud)

notification_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

<GridView
    android:id="@+id/grid_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="64dp"
    android:verticalSpacing="0dp"
    android:columnWidth="192dp"
    android:numColumns="auto_fit"
    />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

应用服务类

public class AppService …
Run Code Online (Sandbox Code Playgroud)

android gridview android-notifications remoteview android-remoteview

5
推荐指数
0
解决办法
340
查看次数

小部件-将图像从URL加载到远程视图中

我正在根据Google“ StackWidget”示例为我的Android应用开发一个简单的小部件:https ://android.googlesource.com/platform/development/+/master/samples/StackWidget/src/com/example/android/stackwidget /StackWidgetService.java

我正在使用滑动图像库,并且尝试在扩展了RemoteViewsService的StackWidgetService类的getViewAt方法上填充ImageView。我正在做这样的事情,但是没有用:

    Handler uiHandler = new Handler(Looper.getMainLooper());
    uiHandler.post(() ->
            Glide.with(context)
            .asBitmap()
            .load(widgetItems.get(position).image_url)
            .into(new SimpleTarget<Bitmap>(512, 512) {
                @Override
                public void onResourceReady(Bitmap bitmap, Transition transition) {
                    rv.setImageViewBitmap(R.id.widget_item_image, bitmap);
                }
            }));
Run Code Online (Sandbox Code Playgroud)

从URL加载图像以从Android小部件填充RemoteView的正确和最佳方法是什么?

android android-widget remoteview android-remoteview android-glide

5
推荐指数
2
解决办法
2738
查看次数

RemoteServiceException 没有额外信息

更新应用程序版本后,我们开始在 Google Play Console 上收到以下崩溃报告:

android.app.RemoteServiceException: 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1867)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6753)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:482)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Run Code Online (Sandbox Code Playgroud)

更多信息:

  • 崩溃仅发生在 API 版本 27 (Android 8.1) 和 28 上。
  • 崩溃发生在多台设备上(主要是 OnePlus6)
  • 崩溃不是通过 Fabric 的 Crashlytics 报告的
  • 最新更新的应用程序已更改compileSdkVersionminSdkVersion28

关于如何解决这个问题有什么想法吗?

android exception remoteview android-remoteview

5
推荐指数
0
解决办法
153
查看次数

单击侦听器上的通知RemoteView

因此,在经过大量的努力之后,我才结束了.我的RemoteViews通知中有一个媒体播放器,我希望能够访问播放,暂停,上一个和下一个按钮.

我知道setOnClickPendingIntent()将用于通知通知.但是,我想知道它是如何工作的.

是否可以让服务处理点击?

我试过这个,但是徒劳无功.我试图让我服务处理播放器的暂停和恢复:

rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);

        Intent intent = new Intent(getApplicationContext(), MusicService.class);
        intent.putExtra(REQUEST_CODE, PAUSE);
        PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
        rm.setPendingIntentTemplate(R.id.pause, pending);

        Notification notif =  new NotificationCompat.Builder(getApplicationContext())
                                 .setOngoing(true)
                                 .setSmallIcon(R.drawable.ic_launcher)
                                 .setContent(rm)
                                 .build();

        NotificationManager mgr = (NotificationManager) getApplicationContext()
                                  .getSystemService(Context.NOTIFICATION_SERVICE);
        mgr.notify(NOTIFICATION_ID, notif);  
Run Code Online (Sandbox Code Playgroud)

我的IBinder是空的.如果这有所作为.

如何从通知中暂停和播放音乐?

android android-service android-pendingintent android-remoteview

4
推荐指数
1
解决办法
6111
查看次数

多次包含 Android RemoteViews 时,在布局内设置 Android RemoteViews 的文本

我参考这个问题: 当我多次重用布局时,如何访问布局内的视图?

我有以下两种布局:

<!-- layout_to_include.xml -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

<!-- widget.xml -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/included_layout_1"
        layout="@layout/layout_to_include"/>

    <include
        android:id="@+id/included_layout_2"
        layout="@layout/layout_to_include"/>

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

通常,您可以在包含的布局中以编程方式访问 TextView,如下所示:

LinearLayout l1 = (LinearLayout) findViewById(R.id.included_layout_1);
((TextView) l1.findViewById(R.id.text_view)).setText("test1");

LinearLayout l2 = (LinearLayout) findViewById(R.id.included_layout_2);
((TextView) l2.findViewById(R.id.text_view)).setText("test2");
Run Code Online (Sandbox Code Playgroud)

但就我而言,我有一个 Android AppWidget,只能通过 RemoteViews 访问:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.text_view, "test1");
Run Code Online (Sandbox Code Playgroud)

这只会更改第一个 TextView 的文本。

我还没有找到任何解决方案,所以我的问题是是否可以在多个包含的布局中设置 TextView 的文本。

android android-widget android-layout android-remoteview

4
推荐指数
1
解决办法
2737
查看次数

ListView不在App Widget中显示数据

我正在尝试为我的应用程序实现一个简单的集合小部件,我试图ListView在一个小部件内部显示但是ListView仍然停留在Loading ...并且从未完成加载,并且我在数据库中有数据并且列表视图仍然是坚持下去.

这是onUpdate我的AppWidgetProvider类的方法:

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    int length = appWidgetIds.length;
    for (int x = 0; x < length; x++){
        RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        Intent intent = new Intent(context,RViewsService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[x]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        remote.setRemoteAdapter(R.id.list,intent);
        remote.setEmptyView(R.id.list,R.id.empty);
        remote.setTextViewText(R.id.title,Utilities.setDayOfWeek());
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        Intent AddmateriaIntent = new Intent(context,AddMateria.class);
        PendingIntent pendingItentForButtonAddMateria = PendingIntent.getActivity(context,0,AddmateriaIntent,0);
        remote.setOnClickPendingIntent(R.id.add,pendingItentForButtonAddMateria);
        remote.setOnClickPendingIntent(R.id.empty, pendingItentForButtonAddMateria);
        appWidgetManager.updateAppWidget(appWidgetIds[x],remote);
    }
   super.onUpdate(context,appWidgetManager,appWidgetIds);
}
Run Code Online (Sandbox Code Playgroud)

我可以检查并且该方法onUpdate完成其工作而没有错误.这里是RemoteViewService和RemoteViewsFactory,它们也没有在logCat上显示错误.

公共类RViewsService扩展了RemoteViewsService {

@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
    return new RViewFactory(getApplicationContext(),intent); …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-listview appwidgetprovider android-remoteview

2
推荐指数
1
解决办法
2011
查看次数