Search in sources :

Example 1 with BrowserController

use of de.baumann.browser.browser.BrowserController in project browser by scoute-dich.

the class HelperUnit method createShortcut.

public static void createShortcut(Context context, String title, String url) {
    Icon icon;
    BrowserController browserController = NinjaWebView.getBrowserController();
    icon = createWithBitmap(browserController.favicon());
    try {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        i.setPackage("de.baumann.browser");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            // code for adding shortcut on pre oreo device
            Intent installer = new Intent();
            installer.putExtra("android.intent.extra.shortcut.INTENT", i);
            installer.putExtra("android.intent.extra.shortcut.NAME", title);
            installer.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), R.drawable.icon_bookmark));
            installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            context.sendBroadcast(installer);
        } else {
            ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
            assert shortcutManager != null;
            if (shortcutManager.isRequestPinShortcutSupported()) {
                ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, url).setShortLabel(title).setLongLabel(title).setIcon(icon).setIntent(new Intent(context, BrowserActivity.class).setAction(Intent.ACTION_VIEW).setData(Uri.parse(url))).build();
                shortcutManager.requestPinShortcut(pinShortcutInfo, null);
            } else {
                System.out.println("failed_to_add");
            }
        }
    } catch (Exception e) {
        System.out.println("failed_to_add");
    }
}
Also used : BrowserController(de.baumann.browser.browser.BrowserController) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) Icon(android.graphics.drawable.Icon)

Aggregations

Intent (android.content.Intent)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 ShortcutManager (android.content.pm.ShortcutManager)1 Icon (android.graphics.drawable.Icon)1 BrowserController (de.baumann.browser.browser.BrowserController)1