下面列出了怎么用android.graphics.drawable.Icon的API类实例代码及写法,或者点击链接到github查看源代码。
@Nullable
private static Drawable maybeLoadDrawable(Icon icon) {
if (icon == null) {
return null;
}
switch (icon.getType()) {
case Icon.TYPE_BITMAP:
return new BitmapDrawable(Resources.getSystem(), icon.getBitmap());
case Icon.TYPE_ADAPTIVE_BITMAP:
return new AdaptiveIconDrawable(null,
new BitmapDrawable(Resources.getSystem(), icon.getBitmap()));
case Icon.TYPE_DATA:
return new BitmapDrawable(
Resources.getSystem(),
BitmapFactory.decodeByteArray(
icon.getDataBytes(), icon.getDataOffset(), icon.getDataLength()));
}
return null;
}
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
ComponentName componentName = new ComponentName(getPackageName(),
ShareActivity.class.getCanonicalName());
ArrayList<ChooserTarget> targets = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Bundle extras = new Bundle();
extras.putInt("directsharekey", i);
targets.add(new ChooserTarget(
"name_" + i,
Icon.createWithResource(this, R.mipmap.ic_logo),
0.5f,
componentName,
extras));
}
return targets;
}
private static Drawable getColoredDrawable(Context ctx, String pkg, Icon icon) {
if (icon == null) return null;
Drawable d = null;
if (pkg == null || PACKAGE_NAME.equals(pkg)) {
final int iconId = (int) XposedHelpers.callMethod(icon, "getResId");
d = SysUiManagers.IconManager.getBasicIcon(iconId);
if (d != null) {
return d;
}
}
d = icon.loadDrawable(ctx);
if (d != null) {
if (SysUiManagers.IconManager.isColoringEnabled()) {
d = SysUiManagers.IconManager.applyColorFilter(d.mutate(),
PorterDuff.Mode.SRC_IN);
} else {
d.clearColorFilter();
}
}
return d;
}
private void setLauncherShortcuts() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if(shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName());
intent.putExtra("launched-from-app", true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions")
.setShortLabel(getString(R.string.label_quick_actions))
.setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon))
.setIntent(intent)
.build();
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
}
}
@TargetApi(Build.VERSION_CODES.M)
void fixIcon(Icon icon, Context pluginContext, boolean isInstall) {
if (icon == null) return;
int type = Reflect.on(icon).get("mType");
// Log.i(TAG, "smallIcon type=" + type);
if (type == 2) {
if (isInstall) {
Reflect.on(icon).set("mObj1", pluginContext.getResources());
Reflect.on(icon).set("mString1", pluginContext.getPackageName());
} else {
Drawable drawable = icon.loadDrawable(pluginContext);
Bitmap bitmap = drawableToBitMap(drawable);
Reflect.on(icon).set("mObj1", bitmap);
Reflect.on(icon).set("mString1", null);
Reflect.on(icon).set("mType", 1);
}
}
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
iconIdle = Icon.createWithResource(this, R.drawable.ic_start_idle).setTint(0x80ffffff);
iconBusy = Icon.createWithResource(this, R.drawable.ic_start_busy);
iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected);
mServiceBoundContext = new ServiceBoundContext(base) {
@Override
protected void onServiceConnected() {
try {
callback.stateChanged(bgService.getState(), bgService.getProfileName(), null);
} catch (RemoteException e) {
e.printStackTrace();
}
}
};
}
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetComponentName,
IntentFilter intentFilter) {
if (sServer != null && sChannel != null) {
if (System.currentTimeMillis() - sSetTime >= SET_TIMEOUT) {
sServer = null;
sChannel = null;
return null;
}
ComponentName componentName = new ComponentName(getPackageName(),
MainActivity.class.getCanonicalName());
List<ChooserTarget> targets = new ArrayList<>();
Bundle extras = new Bundle();
extras.putString(MainActivity.ARG_SERVER_UUID, sServer.toString());
extras.putString(MainActivity.ARG_CHANNEL_NAME, sChannel);
targets.add(new ChooserTarget(sChannel,
Icon.createWithResource(this, R.drawable.ic_direct_share),
1.f, componentName, extras));
return targets;
}
return null;
}
private void updateTileState(int state) {
Tile tile = getQsTile();
if (tile != null) {
tile.setState(state);
Icon icon = tile.getIcon();
switch (state) {
case Tile.STATE_ACTIVE:
icon.setTint(Color.WHITE);
break;
case Tile.STATE_INACTIVE:
case Tile.STATE_UNAVAILABLE:
default:
icon.setTint(Color.GRAY);
break;
}
tile.updateTile();
}
}
private void updateTileState(int state) {
Tile tile = getQsTile();
if (tile != null) {
tile.setState(state);
Icon icon = tile.getIcon();
switch (state) {
case Tile.STATE_ACTIVE:
icon.setTint(Color.WHITE);
break;
case Tile.STATE_INACTIVE:
case Tile.STATE_UNAVAILABLE:
default:
icon.setTint(Color.GRAY);
break;
}
tile.updateTile();
}
}
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addRemoteToAppShortcuts(Context context, RemoteItem remoteItem, String id) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager == null) {
return;
}
Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName());
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id)
.setShortLabel(remoteItem.getName())
.setIcon(Icon.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
.setIntent(intent)
.build();
shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static Icon getShortcutsIcon(Context context,
@DrawableRes int id, @DrawableRes int foregroundId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
DisplayUtils utils = new DisplayUtils(context);
int size = (int) Math.min(utils.dpToPx(108), 288);
Bitmap bitmap = ImageHelper.loadBitmap(context, foregroundId, new int[] {size, size});
return Icon.createWithAdaptiveBitmap(bitmap);
} catch (ExecutionException | InterruptedException ignored) {
}
}
return Icon.createWithResource(context, id);
}
public static Icon generateThemedIcon(Context context, int iconId) {
if (PreferenceUtil.getInstance().coloredAppShortcuts()) {
return generateUserThemedIcon(context, iconId).toIcon();
} else {
return generateDefaultThemedIcon(context, iconId).toIcon();
}
}
@ReactMethod
@TargetApi(25)
public void setShortcutItems(ReadableArray items) {
if (!isShortcutSupported() || items.size() == 0) {
return;
}
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
return;
}
Context context = getReactApplicationContext();
List<ShortcutInfo> shortcuts = new ArrayList<>(items.size());
for (int i = 0; i < items.size(); i++) {
ShortcutItem item = ShortcutItem.fromReadableMap(items.getMap(i));
int iconResId = context.getResources()
.getIdentifier(item.icon, "drawable", context.getPackageName());
Intent intent = new Intent(context, currentActivity.getClass());
intent.setAction(ACTION_SHORTCUT);
intent.putExtra(SHORTCUT_ITEM, item.toPersistableBundle());
shortcuts.add(new ShortcutInfo.Builder(context, "id" + i)
.setShortLabel(item.title)
.setLongLabel(item.title)
.setIcon(Icon.createWithResource(context, iconResId))
.setIntent(intent)
.build());
}
getReactApplicationContext().getSystemService(ShortcutManager.class).setDynamicShortcuts(shortcuts);
}
@RequiresApi(Build.VERSION_CODES.N_MR1)
public ShortcutInfo getShortcutInfo(@NonNull String id, @NonNull String shortLabel, String longLabel, @NonNull Icon icon, @NonNull String action, Uri data) {
ShortcutInfo.Builder shortcutInfoBuilder = new ShortcutInfo.Builder(getApplicationContext(), action)
.setShortLabel(shortLabel)
.setIcon(icon)
.setIntent(getShortcutIntet(action, null));
if (longLabel != null) shortcutInfoBuilder.setLongLabel(longLabel);
return shortcutInfoBuilder.build();
}
private void updateView(boolean displayToast, boolean init) {
Tile tile = getQsTile();
if (BaseMethod.isAccessibilitySettingsOn(this)) {
boolean KeyBlocked = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Config.ENABLED_KEYBLOCK, false);
if (init) {
if (KeyBlocked) {
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(Icon.createWithResource(this, R.drawable.ic_notification_blocked));
} else {
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(Icon.createWithResource(this, R.drawable.ic_notification_not_blocked));
}
} else {
if (tile.getState() == Tile.STATE_ACTIVE) {
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(Icon.createWithResource(this, R.drawable.ic_notification_not_blocked));
} else if (tile.getState() == Tile.STATE_INACTIVE) {
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(Icon.createWithResource(this, R.drawable.ic_notification_blocked));
}
}
} else {
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(Icon.createWithResource(this, R.drawable.ic_notification_not_blocked));
if (displayToast) {
BaseMethod.RunAccessibilityService(this);
}
}
tile.updateTile();
}
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
if (!EventReceiver.hasEnabledAccounts(this)) {
return chooserTargets;
}
final Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction("contact_chooser");
Compatibility.startService(this, intent);
bindService(intent, this, Context.BIND_AUTO_CREATE);
try {
waitForService();
final ArrayList<Conversation> conversations = new ArrayList<>();
if (!mXmppConnectionService.areMessagesInitialized()) {
return chooserTargets;
}
mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter));
final ComponentName componentName = new ComponentName(this, ConversationsActivity.class);
final int pixel = AvatarService.getSystemUiAvatarSize(this);
for (Conversation conversation : conversations) {
if (conversation.sentMessagesCount() == 0) {
continue;
}
final String name = conversation.getName().toString();
final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size();
final Bundle extras = new Bundle();
extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
if (chooserTargets.size() >= MAX_TARGETS) {
break;
}
}
} catch (InterruptedException e) {
}
unbindService(this);
return chooserTargets;
}
private static ShortcutInfo createShortcutInfo(Activity activity, SoundProfile profile) {
return new ShortcutInfo.Builder(activity.getApplicationContext(), profileToShortcutId(profile))
.setIntent(MainActivity.createOpenProfileIntent(activity, profile))
.setShortLabel(profile.name)
.setLongLabel(profile.name)
.setDisabledMessage("Login to open this")
.setIcon(Icon.createWithResource(activity.getApplicationContext(), R.mipmap.ic_launcher_new))
.build();
}
private void updateLauncherShortcut() {
// We will have one dynamic shortcut - to whichever stream was played last
new Thread(new Runnable() {
@Override
public void run() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
JsonChannel jsonChannel = ChannelDatabase.getInstance(getApplicationContext())
.findChannelByMediaUrl(urlStream);
if (jsonChannel == null) {
// Don't create a shortcut because we don't have metadata
return;
}
Log.d(TAG, "Adding dynamic shortcut to " + jsonChannel.getName());
String logo = ChannelDatabase.getNonNullChannelLogo(jsonChannel);
try {
Bitmap logoBitmap = Glide.with(getApplicationContext())
.load(logo)
.asBitmap()
.into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
shortcutManager.removeAllDynamicShortcuts();
Intent playVideo = new Intent(getApplicationContext(), CumulusVideoPlayback.class);
playVideo.setAction("play");
playVideo.putExtra(KEY_VIDEO_URL, urlStream);
ShortcutInfo shortcut = new ShortcutInfo.Builder(CumulusVideoPlayback.this, "id1")
.setShortLabel(jsonChannel.getName()+"")
.setLongLabel(jsonChannel.getNumber() + " - " + jsonChannel.getName())
.setIcon(Icon.createWithBitmap(logoBitmap))
.setIntent(playVideo)
.build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}).start();
}
public ShortcutHelper createShortcut(@NonNull CharSequence shortLabel, @NonNull CharSequence longLabel, @NonNull int iconResource, @NonNull Intent[] intents) {
if (Build.VERSION.SDK_INT < 25) {
return this;
}
String shortcutId = shortLabel.toString().replaceAll("\\s+","").toLowerCase() + "_shortcut";
ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, shortcutId)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(Icon.createWithResource(mActivity, iconResource))
.setIntents(intents)
.build();
mShortcutInfos.add(shortcut);
return this;
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void testShortCut(Context context) {
//(若考虑兼容性可用ShortcutManagerCompat)
ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
boolean requestPinShortcutSupported = shortcutManager.isRequestPinShortcutSupported();
Log.d("realmo", "启动器是否支持固定快捷方式: "+requestPinShortcutSupported);
if (requestPinShortcutSupported) {
Intent shortcutInfoIntent = new Intent(context, ShortCutActvivity.class);
shortcutInfoIntent.setAction(Intent.ACTION_VIEW);
ShortcutInfo info = new ShortcutInfo.Builder(context, "tzw")
.setIcon(Icon.createWithResource(context, R.mipmap.momo))
.setShortLabel("O系统短")
.setLongLabel("O系统长")
.setIntent(shortcutInfoIntent)
.build();
//当添加快捷方式的确认弹框弹出来时,将被回调CallBackReceiver里面的onReceive方法
PendingIntent shortcutCallbackIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, CallBackReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
shortcutManager.requestPinShortcut(info, shortcutCallbackIntent.getIntentSender());
}
}
/**
* Get the icon to be used for this printer. If no per printer icon is available, the printer's
* service's icon is returned. If the printer has a custom icon this icon might get requested
* asynchronously. Once the icon is loaded the discovery sessions will be notified that the
* printer changed.
*
* @param context The context that will be using the icons
* @return The icon to be used for the printer or null if no icon could be found.
* @hide
*/
@TestApi
public @Nullable Drawable loadIcon(@NonNull Context context) {
Drawable drawable = null;
PackageManager packageManager = context.getPackageManager();
if (mHasCustomPrinterIcon) {
PrintManager printManager = (PrintManager) context
.getSystemService(Context.PRINT_SERVICE);
Icon icon = printManager.getCustomPrinterIcon(mId);
if (icon != null) {
drawable = icon.loadDrawable(context);
}
}
if (drawable == null) {
try {
String packageName = mId.getServiceName().getPackageName();
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
ApplicationInfo appInfo = packageInfo.applicationInfo;
// If no custom icon is available, try the icon from the resources
if (mIconResourceId != 0) {
drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
}
// Fall back to the printer's service's icon if no per printer icon could be found
if (drawable == null) {
drawable = appInfo.loadIcon(packageManager);
}
} catch (NameNotFoundException e) {
}
}
return drawable;
}
/**
* Provide a new icon for a printer. Can be called more than once to update the icon.
*
* @param icon The new icon for the printer or null to unset the current icon
* @return true iff the icon could be updated
*/
public boolean onCustomPrinterIconLoaded(@Nullable Icon icon) {
try {
mObserver.onCustomPrinterIconLoaded(mPrinterId, icon);
} catch (RemoteException e) {
Log.e(LOG_TAG , "Could not update icon", e);
return false;
}
return true;
}
/** {@hide} */
@Deprecated
public RecoverableSecurityException(Throwable cause, CharSequence userMessage,
CharSequence userActionTitle, PendingIntent userAction) {
this(cause, userMessage,
new RemoteAction(
Icon.createWithResource("android",
com.android.internal.R.drawable.ic_restart),
userActionTitle, userActionTitle, userAction));
}
private void showStateOff() {
Log.d(TAG, "showStateOff");
final Tile tile = getQsTile();
if (tile.getState() == Tile.STATE_INACTIVE) {
return;
}
final Context context = this;
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(Icon.createWithResource(context, R.drawable.ic_qs_network_adb_off));
tile.setLabel(context.getString(R.string.app_name));
tile.updateTile();
}
/**
* @hide
*/
public Slice createPermissionSlice(Context context, Uri sliceUri,
String callingPackage) {
PendingIntent action;
mCallback = "onCreatePermissionRequest";
Handler.getMain().postDelayed(mAnr, SLICE_BIND_ANR);
try {
action = onCreatePermissionRequest(sliceUri);
} finally {
Handler.getMain().removeCallbacks(mAnr);
}
Slice.Builder parent = new Slice.Builder(sliceUri);
Slice.Builder childAction = new Slice.Builder(parent)
.addIcon(Icon.createWithResource(context,
com.android.internal.R.drawable.ic_permission), null,
Collections.emptyList())
.addHints(Arrays.asList(Slice.HINT_TITLE, Slice.HINT_SHORTCUT))
.addAction(action, new Slice.Builder(parent).build(), null);
TypedValue tv = new TypedValue();
new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault_Light)
.getTheme().resolveAttribute(android.R.attr.colorAccent, tv, true);
int deviceDefaultAccent = tv.data;
parent.addSubSlice(new Slice.Builder(sliceUri.buildUpon().appendPath("permission").build())
.addIcon(Icon.createWithResource(context,
com.android.internal.R.drawable.ic_arrow_forward), null,
Collections.emptyList())
.addText(getPermissionString(context, callingPackage), null,
Collections.emptyList())
.addInt(deviceDefaultAccent, SUBTYPE_COLOR,
Collections.emptyList())
.addSubSlice(childAction.build(), null)
.build(), null);
return parent.addHints(Arrays.asList(Slice.HINT_PERMISSION_REQUEST)).build();
}
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
return new ShortcutInfo.Builder(context, id)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(icon)
.setIntent(intent)
.build();
}
@TargetApi(Build.VERSION_CODES.N_MR1)
private ShortcutInfo getShortcutInfo(Contact contact) {
return new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact))
.setShortLabel(contact.getDisplayName())
.setIntent(getShortcutIntent(contact))
.setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact)))
.build();
}
@TargetApi(26)
private static void doCreateShortcut(Context context, String appName, Drawable draw, Intent intent) {
ShortcutManager shortcutManager = Objects.requireNonNull(context.getSystemService(ShortcutManager.class));
if (shortcutManager.isRequestPinShortcutSupported()) {
Bitmap bitmap = getBitmapFromDrawable(draw);
intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, appName)
.setShortLabel(appName)
.setLongLabel(appName)
.setIcon(Icon.createWithBitmap(bitmap))
.setIntent(intent)
.build();
shortcutManager.requestPinShortcut(shortcutInfo, null);
} else {
new AlertDialog.Builder(context)
.setTitle(context.getText(R.string.error_creating_shortcut))
.setMessage(context.getText(R.string.error_verbose_pin_shortcut))
.setPositiveButton(context.getText(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Just close dialog don't do anything
dialog.cancel();
}
})
.show();
}
}
/**
* Creates a public version of the notification to be displayed in sensitive contexts, such as
* on the lockscreen, displaying just the site origin and badge or generated icon.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Notification createPublicNotification(Context context) {
// Use a non-compat builder because we want the default small icon behaviour.
ChromeNotificationBuilder builder =
NotificationBuilderFactory
.createChromeNotificationBuilder(
false /* preferCompat */, ChannelDefinitions.CHANNEL_ID_SITES)
.setContentText(context.getString(
org.chromium.chrome.R.string.notification_hidden_text))
.setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
// On N, 'subtext' displays at the top of the notification and this looks better.
builder.setSubText(mOrigin);
} else {
// Set origin as title on L & M, because they look odd without one.
builder.setContentTitle(mOrigin);
// Hide the timestamp to match Android's default public notifications on L and M.
builder.setShowWhen(false);
}
// Use the badge if provided and SDK supports it, else use a generated icon.
if (mSmallIconBitmap != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// The Icon class was added in Android M.
Bitmap publicIcon = mSmallIconBitmap.copy(mSmallIconBitmap.getConfig(), true);
builder.setSmallIcon(Icon.createWithBitmap(publicIcon));
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && mOrigin != null) {
// Only set the large icon for L & M because on N(+?) it would add an extra icon on
// the right hand side, which looks odd without a notification title.
builder.setLargeIcon(mIconGenerator.generateIconForUrl(mOrigin.toString(), true));
}
return builder.build();
}
public static void testNotification(String text) {
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final Notification.Builder mBuilder = new Notification.Builder(xdrip.getAppContext());
mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));
mBuilder.setContentTitle("Test Number Graphic");
mBuilder.setContentText("Check the number is visible");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mBuilder.setTimeoutAfter(Constants.SECOND_IN_MS * 30);
} else {
JoH.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
JoH.cancelNotification(Constants.NUMBER_TEXT_TEST_ID);
}
}, Constants.SECOND_IN_MS * 30);
}
mBuilder.setOngoing(false);
mBuilder.setVibrate(vibratePattern);
int mNotificationId = Constants.NUMBER_TEXT_TEST_ID;
final NotificationManager mNotifyMgr = (NotificationManager) xdrip.getAppContext().getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
JoH.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
}, 1000);
} else {
JoH.static_toast_long("Not supported below Android 6");
}
}
}