我有一个AppWidget,我想在Lollipop前设备上使用VectorDrawables.VectorDrawableCompat不能与我创建的RemoteViews一起使用.
为了保持我的应用APK大小,我不想为旧的API平台添加我的drawables的替代PNG版本.
我怎样才能做到这一点?
android android-appcompat remoteview android-support-library android-vectordrawable
最近我收到越来越多的用户收到RemoteServiceException错误的报告.我每次给出的堆栈跟踪如下:
android.app.RemoteServiceException: Bad notification posted from package com.smithyproductions.fasttracks: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.smithyproductions.fasttracks id=311095 tag=null score=0 notn=Notification(pri=0 contentView=com.smithyproductions.fasttracks/0x7f03007d vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) user=UserHandle{0})
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5341)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:929)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
at dalvik.system.NativeStart.main(NativeStart.java)
Run Code Online (Sandbox Code Playgroud)
我似乎永远无法在HTC Sensation或HTC One X上重现这个问题,这让我相信它可能是特定于设备的.我从以下设备收到了此错误的报告:
...而且他们都在运行Android 4.2.1 - 也许这个版本的Android存在错误?
我已经搜索过具有类似问题的人的互联网和StackOverflow,虽然有很多人在这个问题上有很多人因为不正确的资源ID或使用不受支持的视图RemoteViews.我不明白怎么可能会是我做错了,如果它适用于设备的98%,但我并不想告诉这些人的问题,有什么我可以做,要么.
就我创建通知的方式而言,我使用NotificationCompat.Builder类和自定义RemoteViews - 基本上它是一个音乐播放器通知,因此它上面也有一些ImageButtons.
这是我设置通知的代码:
PendingIntent pi = PendingIntent.getActivity(
getApplicationContext(), 0, new Intent(getApplicationContext(), Showcase.class),
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews smallContentView = new RemoteViews(getPackageName(),
R.layout.notif_layout); …Run Code Online (Sandbox Code Playgroud) 我希望从对象中获取尽可能多的信息StatusBarNotification.现在,唯一可以访问的"可靠"信息是tickerText-property.我正在使用以下代码来获取通知的标题和文本RemoteViews,但很多时候,标题和/或文本将只是空:-(:
//Get the title and text
String mTitle = "";
String mText = "";
try {
RemoteViews remoteView = sbn.getNotification().contentView;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup localView = (ViewGroup) inflater.inflate(remoteView.getLayoutId(), null);
remoteView.reapply(getApplicationContext(), localView);
TextView tvTitle = (TextView) localView.findViewById(android.R.id.title);
TextView tvText = (TextView) localView.findViewById(16908358);
mTitle = (String)tvTitle.getText();
mText = (String)tvText.getText();
} catch (Exception e){
Log.e(TAG, "Error getting notification title/text: " + e);
}
Run Code Online (Sandbox Code Playgroud)
有没有替代方案(更可靠)?我可以"手动编码""热门"通知(如Gmail,短信等)的资源ID,但这可能会在这些应用程序更新时随时中断.谢谢!
我正在创建一些自定义的remoteViews,为了将自定义视图和布局绘制到与通知面板一样宽的位图,我需要它的确切宽度.
由于每个供应商都会更改通知面板的宽度,并且在大多数情况下会根据方向进行更改,因此很难找到常规模式.
有没有办法得到它的宽度?
粉红色部分是纯粹的remoteViews,底部是imageview,我将自定义视图绘制到它,因为我没有父宽度,所有子视图都会崩溃.
android android-custom-view android-notifications remoteview
我正在为我的应用程序创建基于StackView的小部件,并且应该显示一些项目.项目数量可能因用户操作而有所不同 - 假设它是某种收藏菜单.我已经实现了RemoteViewsFactory后代来为StackView生成视图:
public class StackRemoteViewsFactory implements RemoteViewsFactory {
private List<Item> data;
private Context context;
public StackRemoteViewsFactory(Context context) {
this.context = context;
data = new DAO(context).getFavouriteCards();
}
@Override
public void onDataSetChanged() {
data = new DAO(context).getWidgetItems(); // refresh widget dataset
}
@Override
public int getCount() {
return data.size();
}
@Override
public RemoteViews getViewAt(int position) {
Item item = data.get(position);
// this is my problem and will be explained below -
// here I'm getting IndexOutOfBoundsException, position = 0
...
} …Run Code Online (Sandbox Code Playgroud) 所以我有一个很好的刷新的app小部件,将一个新的位图加载到一个ImageView常规的发条中.然后,在某些时候,默默地,它会停止更新.我可以从日志和我的代码正在查询的服务器上的活动中看出,小部件实际上仍在继续定期触发(通过播放的广播onReceive(),并按预期执行其操作.唯一没有发生的事情是小部件内容没有更新.
因此,在小部件触发时执行的代码中,我正在创建一个新的RemoteView并向其添加内容,包括通过加载新的位图remoteViews.setImageViewBitmap(imageViewID, bmp),然后最终调用appWidgetManager.updateAppWidget(appWidgetId, remoteViews)以更新小部件内容.很好地工作......直到它停止工作.
我不确定要发布什么代码,因为99%的情况下这个东西工作得很好,但偶尔updateAppWidget()停止工作,没有明显的原因.似乎这是一个系统问题,而不是我的代码中的错误,但我可能是错的.
唯一似乎可能提示这一点的是当连接发生变化时,例如从无信号到WiFi,可能经常发生这种变化.在这些情况下似乎发生了更多.
一旦小部件冻结,唯一解冻它的是重启设备.如果不重新启动,即使删除小部件并添加新小部件也不起作用.实际上,添加一个新的小部件会导致死小部件甚至不响应单击以打开Config Activity,大概是因为remoteViews.setOnClickPendingIntent(R.id.widget, configPendingIntent)被忽略了,就像RemoteViews我仔细构造和发送到的其他内容一样appWidgetManager.updateAppWidget().
它似乎与其他许多人描述的一样:
https://code.google.com/p/android/issues/detail?id=28216
到目前为止似乎没有已知的治疗方法.https://code.google.com/p/android/issues/detail?id=28216#c56上的帖子似乎提供了一些承诺,但我尝试过AppWidgetHost.startListening()在各个地方打电话,包括定期通过重复闹钟看看我是否可以启动小部件,但似乎没有任何工作.
其他用户(而不是开发人员)似乎也看到了这个问题:http://androidforums.com/threads/clock-widget-keeps-freezing-please-help.530333/
有任何想法吗?它正在慢慢地让我发疯!
android google-api remoteview appwidgetprovider android-appwidget
我正在使用Glide从服务器上加载所有图像,但是我正在尝试以正确的方式设置它们以进行通知和RemoteControlClientCompat(这是锁定屏幕的酷事).我正在开发一个音乐播放器,所以每次更改一首歌时,通知的歌曲封面都必须改变.我有这个代码,它第一次工作(虽然图像是从url或drawable加载),但不是第二次调用时.图像不会改变!更改歌曲时会调用CustomNotification.并且在启动活动时调用RegisterRemoteClient.
如果这不是正确的方法,请说明如何.
public void CustomNotification() {
Log.d(TAG, "Set custom notification");
simpleRemoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_custom);
expandedRemoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_big);
mNotification = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_main_logo)
.setTicker(mSongTitle + " - " + mSongAuthors)
.setContentTitle(mSongTitle).build();
setRemoteListeners(simpleRemoteView);
setRemoteListeners(expandedRemoteView);
try {
//Check if playingSong has a cover url, if not set one from drawable
if(!playingSong.has("cover")){
mDummyAlbumArt = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
mDummyAlbumArt2 = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
mDummyAlbumArt3 = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
}else {
Glide.with(MainActivity.context)
.load(API.imgUrl(playingSong.getString("cover_img")))
.asBitmap()
.into(new SimpleTarget<Bitmap>(100, 100) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
mDummyAlbumArt = bitmap; …Run Code Online (Sandbox Code Playgroud) notifications android remoteview lockscreenwidget android-glide
我有一个应用程序小部件,我想添加视图(TextView等等),RemoteView但它永远不会出现.
这里是代码:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
views.addView(views.getLayoutId(), newView);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这就是我最终做的事情:
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
ComponentName thisWidget = new ComponentName(this,WidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, newView);
Run Code Online (Sandbox Code Playgroud) 基本上我想做的是将一个自定义的parcelable对象通过intent传递给RemoteViewsService,从而传递给我的RemoteViewsFactory.出于某种原因,这根本不起作用:S每当我尝试这样做时,小部件最终会显示"问题加载小部件"文本.
当我尝试相同的事情,但我没有将它传递给RemoteViewsService,而是将其传递给常规Activity,它完全按预期工作.
我试图在网上找到我的答案,但我一直没有成功,因此我现在发帖在这里希望得到帮助.
我一直试图让这个在我的主程序中运行一段时间.但我无法弄明白.所以我试着将它煮沸,看看我是否在某种程度上做错了什么.我成功地重新创建了这个问题,我重新创建问题的基础来自CommonsGuy的LoremWidget(https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget)和一个随机的可以说明的例子(http ://prasanta-paul.blogspot.dk/2010/06/android-parcelable-example.htm l)我已经修改过以显示我的问题.(希望我不会遇到麻烦,在这两个链接上使用了代码)
下面是随机文件主机上传的完整代码,以防有人想要测试我正在谈论的内容:http: //www.filedropper.com/remoteviewserviceparcelerrorexample
总结一下我的问题:
为什么我不能将我的parcelable对象(单独或包装在ArrayList中)传递给我的RemoteViewsService?(当相同的代码与Activity一起工作时)
我真的希望有人能够帮助我.现在,在我的主程序中,我将序列化到内部存储,然后从RemoteViewsService再次反序列化,之后我已经阅读了所有内容,这是非常有效的!
编辑:记住,由于某种原因,在我的主程序中,如果我传递一个自定义对象,将ArrayList和Strings设置为null,并将布尔值全部设为false(基本上是对象在创建时的外观),小部件看起来很正常(即没有"问题加载小部件"消息).
编辑:看了一下外观(没有过滤到我正在运行的应用程序)我现在看到一些错误(猜测我最好学会在未获得任何文件的情况下将其全部未过滤:) :):
11-13 17:14:27.268: D/AndroidRuntime(8840): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-13 17:14:27.268: D/AndroidRuntime(8840): CheckJNI is ON
11-13 17:14:27.340: D/AndroidRuntime(8840): Calling main entry com.android.commands.pm.Pm
11-13 17:14:27.348: W/ActivityManager(90): No content provider found for permission revoke: file:///data/local/tmp/com.commonsware.android.appwidget.lorem.LoremActivity.apk
11-13 17:14:27.348: W/ActivityManager(90): No content provider found for permission revoke: file:///data/local/tmp/com.commonsware.android.appwidget.lorem.LoremActivity.apk
11-13 17:14:27.356: I/PackageManager(90): Removing non-system package:com.commonsware.android.appwidget.lorem
11-13 17:14:27.360: I/ActivityManager(90): Force stopping package com.commonsware.android.appwidget.lorem uid=10034
11-13 17:14:27.360: I/ActivityManager(90): Killing …Run Code Online (Sandbox Code Playgroud) 我需要制作一个自定义的大型通知,底部有大约3个图像,顶部有图像标题和2个文本视图.
像这样的东西:

上部区域需要看起来与本机通知完全相同,以使它在两者之间有一个很好的过渡.
底部区域是动态的,照片放在那里(使用位图).
一旦我使用自定义视图,它实际上包含整个布局,包括上部区域.
我想到了两个解决方案:
为了创建位图,我可以使用这样的东西:
final int widthScreen = getResources().getDisplayMetrics().widthPixels;
final int width = Math.min(widthScreen, (int) convertDpToPixels(this, 256));
final Bitmap outputBitmap = Bitmap.createBitmap(width, width / 3, Config.ARGB_8888);
final Canvas canvas = new Canvas(outputBitmap);
final int[] imagesResIds = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3 };
final Paint paint = new Paint();
for (int i = 0; i < 3; ++i) {
final Bitmap b = BitmapFactory.decodeResource(getResources(), imagesResIds[i]);
canvas.drawBitmap(b, null, new Rect(i * (width / 3), …Run Code Online (Sandbox Code Playgroud) android android-custom-view android-layout android-notifications remoteview