Marshmallow不显示我的自定义模拟时钟小部件

时间:2017-01-17 08:13:13

标签: android-widget android-6.0-marshmallow

我创建了自定义模拟时钟,我想在小部件中显示。该模拟时钟在Api 16+中可见,但在棉花糖(Api 23)中不可见。棉花糖允许创建小部件但不在主屏幕上显示我的模拟时钟。 在marshmallow中是否有任何权限来显示我的自定义模拟小部件? 这是我的Widget类

'public class Widget extends AppWidgetProvider {
private Intent mUpdateService;
@Override
public void onReceive(Context context, Intent intent) {      if(intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_DISABLED)) {
        mUpdateService = new Intent();}else{
        if (mUpdateService == null)
            mUpdateService = new Intent(context, UpdateService.class);
        context.startService(mUpdateService);
 }
}
    public static class UpdateService extends Service {
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        private boolean isScreenOn = true;
        @Override
        public void onReceive(Context context, Intent intent) {
            String key = intent.getAction();
            if (key.equals(Intent.ACTION_SCREEN_ON)) {
                isScreenOn = true;
                updateWidget();
            } else if (key.equals(Intent.ACTION_SCREEN_OFF)) {
                isScreenOn = false;
            } else if (isScreenOn) {
                updateWidget();
            }
        }
    };
    public RemoteViews mRemoteViews;
    public WidgetAnalogClock widgetAnalogClock;
    @Override
    public void onCreate() {
        mRemoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout);
        widgetAnalogClock = new WidgetAnalogClock(getApplicationContext());

        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        registerReceiver(mReceiver, filter);
    }

    @Override
    public void onDestroy() {
    unregisterReceiver(mReceiver);}
    @Override
    public void onStart(Intent intent, int startId) {
    updateWidget();}
    private void updateWidget(){
        WidgetAnalogClock myView=new WidgetAnalogClock(getApplicationContext());
        mRemoteViews=new RemoteViews(getApplicationContext().getPackageName(),R.layout.widget_layout);
        myView.measure(150, 150);
        myView.layout(0, 0, 750, 750);
        myView.setDrawingCacheEnabled(true);
        Bitmap bitmap = myView.getDrawingCache();
        mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);
        AppWidgetManager.getInstName(this, Widget.class), mRemoteViews);
        bitmap = myView.getDrawingCache();
        mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);}
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }
}

}`

0 个答案:

没有答案