标签: remoteview

RemoteView 和 setGravity

我有一个 android 小部件,它TextView在 a 中显示 a FrameLayout。填充TextView整个父布局。我想要做的是,它能够在运行时更改文本将出现在TextView.

目前,我会通过改变 TextView 上的重力来做到这一点...它甚至有一个setGravity(int)方法,应该与 RemoteView 完美配合(我在一个小部件中,还记得吗?)..无论如何理论上都是如此。

不幸的是,这会返回一个错误。关于“不能setGravity(int)在这里运行”之类的东西。如果需要,将使用确切的错误消息进行更新

我正在使用这个片段:

myRemoteView.setInt(R.id.myTextView, "setGravity", myGravity);
Run Code Online (Sandbox Code Playgroud)

有人尝试过这个吗?有什么想法吗?

android android-widget remoteview

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

如何以编程方式更改 RemoteViews 中 ViewFlipper 的“android:autoStart”属性?

我正在构建一个具有多个视图并翻转视图的 appWidget。基本上,它正在工作。但我不知道如何以编程方式停止 RemoteViews 中的视图翻转。

这是用于翻转的 xml 布局

<ViewFlipper android:id="@+id/vf_slot_0"
    android:layout_width="fill_parent" android:layout_height="75dp"
    android:autoStart="true"
    android:flipInterval="10000">
Run Code Online (Sandbox Code Playgroud)

这是代码

RemoteViews mViews = new RemoteViews(context.getPackageName(), R.id.flipping_view);
mViews.setBoolean(R.id.vf_slot_0, "setAutoStart", false);
mViews.setInt(R.id.vf_slot_0, "setFlipInterval", 1000);
Run Code Online (Sandbox Code Playgroud)

'setFlipInterval' 正在工作。我可以使用此代码以编程方式更改翻转间隔。但是“setAutoStart”不是。并收到此错误..

08-19 01:45:38.821: WARN/AppWidgetHostView(2889): android.widget.RemoteViews$ActionException: view: android.widget.ViewFlipper can't use method with RemoteViews: setAutoStart(boolean)
Run Code Online (Sandbox Code Playgroud)

想知道为什么我不能使用“setAutoStart”而我可以使用“setFlipInterval”。有什么方法可以以编程方式开始或停止在我的 appWidget 中翻转图像吗?

android viewflipper remoteview android-appwidget

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

动态添加的 RemoteView 上的布局权重

在我的小部件中,我使用以下内容将项目 (R.layout.widget_item) 动态添加到我的主小部件布局中定义的 LinearLayout:

//--  Main widget layout
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_design);

//--  Add to main layout
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_item);
views.addView(R.id.view_container, newView);
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何在 newView 上动态设置“android:layout_weight”属性?

java android android-layout remoteview

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

从RemoteViews对象中检索文本

我需要从RemoteViews对象中检索一些文本.它可以让我得到LayoutId,但我不知道如何从一个文本TextView是在此RemoteView(即通知).

也是RemoteView唯一包含setter,但没有getter,所以我想我必须使用LayoutId(不知何故).

你能帮帮我吗?谢谢!

/编辑:我之所以这样问,是因为我有一个AccessibilityService检索通知的原因.因此,这是检索值的唯一方法.

/ edit2:我使用此代码接收通知:

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        List<CharSequence> notificationList = event.getText();
        for (int i = 0; i < notificationList.size(); i++) {
            Toast.makeText(this.getApplicationContext(), notificationList.get(i), 1).show();
        }
        if (!(parcel instanceof Notification)) {
            return;
        }
        final Notification notification = (Notification) parcel;
        doMoreStuff();

    }
}
Run Code Online (Sandbox Code Playgroud)

使用该notification对象,我可以访问a RemoteViews(notification.contentView)和a PendingIntent(notification.contentIntent).要获得layoutId,我可以打电话contentView.getLayoutId()

android remoteview

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

如何在不重建所有RemoteView的情况下部分更新应用程序窗口小部件中的视图

我正在实现一个app小部件,我希望能够在小部件布局中更改单个视图的属性,而无需RemoteViews从头开始重建所有内容,这涉及加载XML等,在某些情况下不需要.有没有办法说"在当前窗口小部件布局中由特定ID标识的视图上更新属性X"?我已经看到班上有一种partiallyUpdateAppWidget方法,AppWidgetManager但是我无法理解,也不是为了这个目的,也不是必须如何使用它.你能帮助我或指向一个有用的链接或例子吗?

android android-widget android-layout remoteview

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

Android远程查看通知

我有一个使用远程视图的android通知栏.我有2个按钮可以播放和暂停音频,还有一个图标可以返回应用程序.我希望能够单击图标(或在2个按钮上的任何位置)并返回到应用程序.这是我的代码

Intent returnIntent = new Intent(_context, SplashScreenActivity.class);
returnIntent.setAction(Intent.ACTION_MAIN);
returnIntent.addCategory(Intent.CATEGORY_LAUNCHER);

PendingIntent remoteViewPendingIntent = PendingIntent.getActivity(_context,1, returnIntent,0);
remoteView.setOnClickPendingIntent(R.id.btnAppIcon, remoteViewPendingIntent);
Run Code Online (Sandbox Code Playgroud)

这一切在Android 4.1上的模拟器中都能正常工作.按下通知中的图标后,它会成功返回到应用程序.但是在Samsung S3上的Android 4.0.3上,Activity会在后台启动,但通知屏幕不会隐藏.我想要在选择图标后清除通知屏幕.我已经尝试在通知中使用Notification.FLAG_AUTO_CANCEL但是没有解决问题.任何帮助将不胜感激.

notifications android remoteview

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

在Widget(RemoteViews)中更改GridView中的numColumns无效

我有一个带有GridView的小部件(可以工作),它以1个或多个列/行显示信息.我想以编程方式设置列数,导致用户选择.如果我将Layout-XML中的numColumns设置为"1",它可以正常工作.如果我尝试以下列方式设置numColumns,它没有任何效果:

    rViews.setInt(R.id.duration_view, "setNumColumns", 1);
Run Code Online (Sandbox Code Playgroud)

布局看起来像这样:

    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/duration_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="64dp"
        android:verticalSpacing="0dp"
        android:columnWidth="192dp"
        android:numColumns="auto_fit"
    />
Run Code Online (Sandbox Code Playgroud)

我的widget onUpdate()方法,使用RemoteAdapter:

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // ....
        Intent intent = new Intent(context, ViewFlipperWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        rViews.setRemoteAdapter(R.id.duration_view, intent);
        rViews.setEmptyView(R.id.duration_view, R.id.empty_view);

        // This doesnt have any effect...:-(
        rViews.setInt(R.id.duration_view, "setNumColumns", 1); 

        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.duration_view);            

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, rViews);

        // ....
        super.onUpdate(context, appWidgetManager, appWidgetIds);
Run Code Online (Sandbox Code Playgroud)

不仅setNumColumns没有效果,其他方法调用也是如此.我做错了什么?

collections android gridview widget remoteview

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

如何在android中以编程方式更改app小部件中的图像

我设计了一个Android应用程序小部件,其中两个ImageView我想要更改图像ImageView时单击图像以及调用方法.现在我用RemoteView 这个

RemoteViews views1 = new RemoteViews(context.getPackageName(),
                R.layout.activity_main);
        views1.setOnClickPendingIntent(R.id.smsImageView, pendIntent1);
        appWidgetManager.updateAppWidget(appWidgetIds, views1);
Run Code Online (Sandbox Code Playgroud)

但我不知道我如何改变imageView 谢谢你的形象.

android android-widget remoteview

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

带有ListView的Android Widget仅显示加载视图

我正在尝试使用ListView实现Android App Widget.我开始关注Google文档但是我遇到了正在显示的加载视图列表,而不是正常的列表项.有没有人有小部件列表视图的经验?

代码与Google文档中的代码相同.我使用ListView而不是StackView作为数据源我使用数据库(这不是问题,数据是正确获得的 - 我通过返回正常的列表项视图而不是默认的加载视图尝试了这一点)

搜索互联网没有帮助我...我也试过这个教程,但它也没有用.我希望有人可以帮助我,提前谢谢!

WidgetProvider.java

public class WidgetProvider extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

        for (int i = 0; i < appWidgetIds.length; i++) {

            Intent intent = new Intent(context, EventWidgetService.class);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
            intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget);
            rv.setRemoteAdapter(android.R.id.list, intent);
            rv.setEmptyView(android.R.id.list, R.id.tvEmptyList);

            appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }
}
Run Code Online (Sandbox Code Playgroud)

WidgetService.java

public class EventWidgetService extends RemoteViewsService {

    @Override …
Run Code Online (Sandbox Code Playgroud)

android android-listview remoteview android-appwidget

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

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
查看次数