天道酬勤,学无止境

android-appwidget

Android: enable/disable app widgets programmatically

问题 问题:有没有办法启用我以编程方式随应用程序提供的一些主屏幕小部件? 例如,拥有“高级”小部件并仅在付款后才能访问它? 正如 Android 文档所说,应该在清单中添加一个广播接收器,以告诉系统应用程序附带一个小部件: <receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/example_appwidget_info" /> </receiver> 但理论上广播接收器也可以通过编程方式添加,那么小部件可以稍后在运行时注册吗? 回答1 PackageManager packageManager = getApplicationContext().getPackageManager(); //To disable widget packageManager.setComponentEnabledSetting(new ComponentName

2022-05-15 09:27:12    分类:技术分享    android   broadcastreceiver   android-widget   android-appwidget

Saving run-time generated NinePatch on external memory

问题 我正在关注这篇文章以在运行时创建九个可绘制的补丁。 我需要将 9patch 图像保存在内部/外部存储器中,以便我可以轻松检索它的 URI 并将其分配给 ImageView。 有谁知道我怎样才能做到这一点? PS Bitmap.compress方法不起作用,因为它将图像保存为常规(不是 9patch)png 文件。 PS 我知道我可以序列化生成的 NinePatch 对象并将其保存到文件中。 但是这样我不能将它分配给 RemoteViews 对象(使用 RemoteViews.setImageViewUri 方法)。 所以我需要将它保存为真正的九个补丁图像。 回答1

2022-05-09 19:50:09    分类:技术分享    android   android-appwidget   nine-patch   remoteview

Detect OnTouch on AppWidget. If is it possible?

问题 在 AppWidget 上检测 OnTouch。 如果有可能吗? 你好! 我正在尝试为 Android 2.1 创建我的第一个 AppWidget,其中客户端可能有机会在我的自定义视图上选择一个项目。 我将为其创建一个自定义视图和一个滑块,客户端可以通过将滑块拉到自定义视图上来进行选择。 为此,我想检测 AppWidget 的 onTouch(以确定 X、Y 坐标),有没有办法做到这一点? 我看到了可以在 AppWidget 中使用的有效小部件列表: 模拟时钟按钮计时器图像按钮图像视图进度条文本视图 ViewFlipper 列表显示网格视图堆栈视图 AdapterViewFlipper 但是它们不符合我的需要。 我用谷歌搜索了这个,但找不到任何可以帮助我的东西。 有没有办法在 AppWidget 中检测 OnTouch? 也许这需要我有一个更新的 API 版本。 回答1 似乎没有办法检测AppWidget上的触摸。RemoteViews 没有检测方法(我们无法为它们注册触摸监听器)。 Mark Murphy(CommonsWare) 在检测小部件的 onTouch 中说: 您没有检测到应用小部件的“触摸”。 但是,您可以通过 RemoteViews 上的 setOnClickPendingIntent() 检测点击。 AFAIK,这适用于 RemoteViews

2022-05-03 22:32:08    分类:技术分享    android   android-appwidget   touch-event   ontouchlistener

Android: enable/disable app widgets programmatically

Question: Is there a way to enable some of the homescreen widgets that I give out with my app programmatically? For example, having a "premium" widget and giving access to it only after payment? As the Android docs say, one should add a broadcast receiver in the manifest to tell the system that there is a widget coming with the app: <receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/example_appwidget_info" /> <

2022-05-03 08:05:28    分类:问答    android   broadcastreceiver   android-widget   android-appwidget

Saving run-time generated NinePatch on external memory

I'm following this post to create nine patch drawable at run-time. I need to save the 9patch image on the internal/external memory, so that i can easily retrieve it's URI and assign it to an ImageView for example. Does anybody know how can I achieve this? P.S. Bitmap.compress method won't work, because it will save the image as a regular (not 9patch) png file. P.S. I know that I can serialize generated NinePatch object and save it to a file. But this way I can't assign it to a RemoteViews object (using RemoteViews.setImageViewUri method). So I need to save it as a real nine patch image.

2022-04-30 02:51:26    分类:问答    android   android-appwidget   nine-patch   remoteview

AppWidget image with rounded corners

So, I am dynamically creating an image within my app by animating various Views that I display to the user in the main layout of my application. Currently I am generating my scene within a RelativeLayout, taking the image of the layout as a bitmap, then saving the bitmap to SD to be accessed by the appwidget via uri. This is all working great, but... in an attmept to create rounded corners for the appwidget image, i've tried using these two snippets that I found here. My Problem: is that this method generates a drawable (whose rounded corners look perfect if displayed as a drawable) but I need

2022-04-29 03:18:18    分类:问答    java   android   bitmap   png   android-appwidget

Detect OnTouch on AppWidget. If is it possible?

Detect OnTouch on AppWidget. If is it possible? Hello! I'm trying to create my first AppWidget for Android 2.1 in which a client may have a chance to select an item on my custom view. I'm going to create a custom view and a slider for it and client may select by pulling slider over the custom view. For this purpose I want to detect onTouch for AppWidget (to determine X-, Y- coordinates), is there way to do this? I saw a list of valid widgets which can be used in AppWidget: AnalogClock Button Chronometer ImageButton ImageView ProgressBar TextView ViewFlipper ListView GridView StackView

2022-04-27 17:35:17    分类:问答    android   android-appwidget   touch-event   ontouchlistener

Setting programmatically the pixel size of a remote ImageVIew?

Let's say that I have a layout that contains <ImageView android:id="@+id/my_id" android:layout_width="123px" android:layout_height="345px" android:padding="0dip" android:scaleType="fitXY" /> which is used in an AppWidget and is set via a RemoteViews. How can I programmatically set the width and height in pixels (overriding the 123 and 345 in the above xml)? (motivation: this image view shows a dynamic png file that is set at runtime via a file URL. If the layout_width and layout_height above are set to wrap_content, the image is displayed scaled down the the device's density(). Setting the

2022-04-17 03:08:09    分类:问答    android   android-widget   android-imageview   android-appwidget

Widget: onUpdate, onReceive - appWidgetManager - not working in v2.3.5 and v3.2.1

I am new to Android applications and hence have a few questions. Using the code below, I am trying action on ImageButton. And it would be important to remember that this is a Widget, not an Activity. I searched online for examples on using ImageButton in a Widget and found very little information. However, this working example seems to have problems with different versions of Android. Now, the code works on old version (2.1-update1) of Android and not in new version of phone(2.3.5) or on Tablet (3.2.1) Working - (2.1-update1, Samsung 5700) Not working - (2.3.5, HTC Desire HD ) Not working - (3

2022-04-16 10:25:24    分类:问答    android   android-widget   widget   android-appwidget