Note that there are some explanatory texts on larger screens.

plurals
  1. POgetAssets from Android Widget
    text
    copied!<p>The issue that I am having is I am trying to draw a custom font onto a widget(AppWidgetProvider). The issue now is that you cannot access ges tAssets() from and extension of AppWidgetProvider. Is there a way around this? Thanks!</p> <p><strong>* UPDATE *</strong> Here is what I have now after the feedback. The Widget doesn't display anything. what should my xml look like for this? Maybe that is where I'm going wrong now...</p> <pre><code>import java.text.DateFormat; import java.util.Date; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Typeface; import android.appwidget.AppWidgetManager; import android.widget.RemoteViews; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Typeface; import android.widget.ImageView; public class ClockWidgetXProvider extends AppWidgetProvider { public Bitmap buildUpdate(String string, Context context) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); Typeface clock = Typeface.createFromAsset(context.getAssets(),"Carre.ttf"); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(clock); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(65); paint.setTextAlign(Align.CENTER); myCanvas.drawText(string, 80, 60, paint); return myBitmap; } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.clockwidget); String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); view.setImageViewBitmap(R.id.time1, buildUpdate(currentDateTimeString, context)); appWidgetManager.updateAppWidget(appWidgetIds, view); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload