Example usage for android.content Intent URI_INTENT_SCHEME

List of usage examples for android.content Intent URI_INTENT_SCHEME

Introduction

In this page you can find the example usage for android.content Intent URI_INTENT_SCHEME.

Prototype

int URI_INTENT_SCHEME

To view the source code for android.content Intent URI_INTENT_SCHEME.

Click Source Link

Document

Flag for use with #toUri and #parseUri : the URI string always has the "intent:" scheme.

Usage

From source file:io.v.android.impl.google.services.beam.BeamActivity.java

@Override
public void onResume() {
    super.onResume();
    NdefMessage msgs[] = null;/*from  w w w .  j  a  va  2  s.co m*/
    Intent intent = getIntent();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
        }
    }
    if (msgs == null) {
        Log.d(TAG, "No ndef messages");
        finish();
        return;
    }
    VBeamManager.Data data = null;
    for (NdefMessage m : msgs) {
        data = VBeamManager.decodeMessage(m);
        if (data != null)
            break;
    }
    if (data == null) {
        Log.w(TAG, "Unable to deserialize data");
        finish();
        return;
    }
    Log.d(TAG, "connecting to " + data.name);
    VContext ctx = V.init(this).withTimeout(Duration.standardSeconds(2));
    Options opts = new Options();

    opts.set(OptionDefs.SERVER_AUTHORIZER, VSecurity.newPublicKeyAuthorizer(data.key));
    IntentBeamerClient client = IntentBeamerClientFactory.getIntentBeamerClient(data.name);
    ListenableFuture<IntentBeamerClient.GetIntentOut> out = client.getIntent(ctx, data.secret, opts);
    Futures.addCallback(out, new FutureCallback<IntentBeamerClient.GetIntentOut>() {
        @Override
        public void onSuccess(IntentBeamerClient.GetIntentOut result) {
            try {
                Log.d(TAG, "got intent " + result.intentUri);
                int flags = 0;
                if (result.intentUri.startsWith("intent:")) {
                    flags = Intent.URI_INTENT_SCHEME;
                } else {
                    flags = Intent.URI_ANDROID_APP_SCHEME;
                }
                Intent resultIntent = Intent.parseUri(result.intentUri, flags);
                resultIntent.putExtra(VBeamManager.EXTRA_VBEAM_PAYLOAD, result.payload);
                startActivity(resultIntent);
                finish();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            t.printStackTrace();
            finish();
        }
    });
}

From source file:Main.java

private static Intent intentFromString(StringBuilder s) {
    CharSequence prefix = extract(s);
    Intent intent = null;/*from  w  w  w  .  jav a  2s .c o  m*/
    if (prefix != null) {
        try {
            String action = toString(extract(s));
            String uri = toString(extract(s));
            intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
            intent.setAction(action);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return intent;
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {
    // setup intent pointing to RemoteViewsService providing the views for the collection
    Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // When intents are compared, the extras are ignored, so we need to
    // embed the extras into the data so that the extras will not be
    // ignored.//from   ww w .  j  a  v a  2s.  co  m
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

    // determine layout (current size) and theme (user pref)
    final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
    final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
    int layoutResId;
    if (isLightTheme) {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
    } else {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
    }

    // build widget views
    RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
    rv.setRemoteAdapter(R.id.list_view, intent);
    // The empty view is displayed when the collection has no items. It
    // should be a sibling of the collection view.
    rv.setEmptyView(R.id.list_view, R.id.empty_view);

    // set the background color
    int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
    rv.setInt(R.id.container, "setBackgroundColor", bgColor);

    // determine type specific values
    final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
    int showsTabIndex;
    int titleResId;
    int emptyResId;
    if (widgetType == WidgetSettings.Type.UPCOMING) {
        // upcoming
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
        titleResId = R.string.upcoming;
        emptyResId = R.string.noupcoming;
    } else if (widgetType == WidgetSettings.Type.RECENT) {
        // recent
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
        titleResId = R.string.recent;
        emptyResId = R.string.norecent;
    } else {
        // favorites
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
        titleResId = R.string.action_shows_filter_favorites;
        emptyResId = R.string.no_nextepisode;
    }

    // change title and empty view based on type
    rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
    if (!isCompactLayout) {
        // only regular layout has text title
        rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
    }

    // app launch button
    final Intent appLaunchIntent = new Intent(context, ShowsActivity.class)
            .putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
    PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent)
            .getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);

    // item intent template, launches episode detail view
    TaskStackBuilder builder = TaskStackBuilder.create(context);
    builder.addNextIntent(appLaunchIntent);
    builder.addNextIntent(new Intent(context, EpisodesActivity.class));
    rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));

    // settings button
    Intent settingsIntent = new Intent(context, ListWidgetConfigure.class)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    rv.setOnClickPendingIntent(R.id.widget_settings,
            PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    return rv;
}

From source file:de.azapps.mirakel.services.NotificationService.java

/**
 * Updates the Notification//  ww w.  j a v a2 s. c o m
 */
public void notifier() {
    if (!MirakelCommonPreferences.useNotifications() && !this.existsNotification) {
        return;
    }

    final Optional<ListMirakel> showList = ListMirakel.get(MirakelCommonPreferences.getNotificationsListId());
    Optional<ListMirakel> openList = ListMirakel.get(MirakelCommonPreferences.getNotificationsListOpenId());
    if (!showList.isPresent()) {
        return;
    }
    if (!openList.isPresent()) {
        openList = showList;
    }

    // Set onClick Intent
    final Optional<Class<?>> main = Helpers.getMainActivity();
    if (!main.isPresent()) {
        return;
    }
    final Intent openIntent = new Intent(this, main.get());
    openIntent.setAction(DefinitionsHelper.SHOW_LIST);
    openIntent.putExtra(DefinitionsHelper.EXTRA_LIST, openList.get());
    openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pOpenIntent = PendingIntent.getActivity(this, 0, openIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final List<Task> todayTasks = showList.get().tasks(false);
    final String notificationTitle;
    final String notificationText;
    if (todayTasks.isEmpty()) {
        notificationTitle = getString(R.string.notification_title_empty);
        notificationText = "";
    } else {
        if (todayTasks.size() == 1) {
            notificationTitle = getString(R.string.notification_title_general_single, showList.get().getName());
        } else {
            notificationTitle = String.format(getString(R.string.notification_title_general), todayTasks.size(),
                    showList.get().getName());
        }
        notificationText = todayTasks.get(0).getName();
    }
    final boolean persistent = MirakelCommonPreferences.usePersistentNotifications();
    // Build notification
    final NotificationCompat.Builder noti = new NotificationCompat.Builder(this)
            .setContentTitle(notificationTitle).setContentText(notificationText)
            .setSmallIcon(R.drawable.ic_mirakel)
            .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext())).setContentIntent(pOpenIntent)
            .setOngoing(persistent);
    // Big View
    if ((todayTasks.size() > 1) && (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)) {
        final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (final Task task : todayTasks) {
            inboxStyle.addLine(task.getName());
        }
        noti.setStyle(inboxStyle);
    }
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);
    notificationManager.notify(DefinitionsHelper.NOTIF_DEFAULT, noti.build());
    if ((todayTasks.isEmpty()) || !MirakelCommonPreferences.useNotifications()) {
        notificationManager.cancel(DefinitionsHelper.NOTIF_DEFAULT);
        this.existsNotification = false;
    } else {
        this.existsNotification = true;
    }
}

From source file:com.battlelancer.seriesguide.api.Action.java

/**
 * Deserializes a {@link Bundle} into a {@link Action} object.
 *///from   w  ww. j a v a 2s.c o m
public static Action fromBundle(Bundle bundle) {
    String title = bundle.getString(KEY_TITLE);
    if (TextUtils.isEmpty(title)) {
        return null;
    }
    int entityIdentifier = bundle.getInt(KEY_ENTITY_IDENTIFIER);
    if (entityIdentifier <= 0) {
        return null;
    }
    Builder builder = new Builder(title, entityIdentifier);

    try {
        String viewIntent = bundle.getString(KEY_VIEW_INTENT);
        if (!TextUtils.isEmpty(viewIntent)) {
            builder.viewIntent(Intent.parseUri(viewIntent, Intent.URI_INTENT_SCHEME));
        }
    } catch (URISyntaxException ignored) {
    }

    return builder.build();
}

From source file:de.azapps.mirakel.reminders.ReminderAlarm.java

private static void createNotification(final Context context, final Task task) {
    Log.w(TAG, task.getName());/*www  .j a  va2  s. co m*/
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    final Optional<Class<?>> main = Helpers.getMainActivity();
    if (!main.isPresent()) {
        return;
    }
    final Intent openIntent = new Intent(context, main.get());

    final Bundle withTask = new Bundle();
    withTask.putParcelable(DefinitionsHelper.EXTRA_TASK, task);
    openIntent.setAction(DefinitionsHelper.SHOW_TASK_REMINDER);
    openIntent.putExtra(DefinitionsHelper.EXTRA_TASK_REMINDER, task);
    openIntent.putExtra(String.valueOf(task.getId()), task.getId());
    openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pOpenIntent = PendingIntent.getActivity(context, 0, openIntent, 0);
    final Intent doneIntent = new Intent(context, TaskService.class);
    doneIntent.setAction(TaskService.TASK_DONE);
    doneIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask);
    doneIntent.putExtra(String.valueOf(task.getId()), task.getId());
    doneIntent.setData(Uri.parse(doneIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pDoneIntent = PendingIntent.getService(context, 0, doneIntent, 0);
    final Intent laterIntent = new Intent(context, TaskService.class);
    laterIntent.setAction(TaskService.TASK_LATER);
    laterIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask);
    laterIntent.putExtra(String.valueOf(task.getId()), task.getId());
    laterIntent.setData(Uri.parse(laterIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pLaterIntent = PendingIntent.getService(context, 0, laterIntent, 0);
    final boolean persistent = MirakelCommonPreferences.usePersistentReminders();
    // Build Notification
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(context.getString(R.string.reminder_notification_title, task.getName()))
            .setContentText(task.getContent()).setSmallIcon(R.drawable.ic_mirakel)
            .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, context)).setContentIntent(pOpenIntent)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setLights(Color.BLUE, 1500, 300)
            .setOngoing(persistent).setDefaults(Notification.DEFAULT_VIBRATE)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .addAction(R.drawable.ic_checkmark_holo_light,
                    context.getString(R.string.reminder_notification_done), pDoneIntent)
            .addAction(android.R.drawable.ic_menu_close_clear_cancel,
                    context.getString(R.string.reminder_notification_later), pLaterIntent);

    final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    final String priority = ((task.getPriority() > 0) ? ("+" + task.getPriority())
            : String.valueOf(task.getPriority()));
    final CharSequence due;
    if (!task.getDue().isPresent()) {
        due = context.getString(R.string.no_date);
    } else {
        due = DateTimeHelper.formatDate(context, task.getDue());
    }
    inboxStyle.addLine(context.getString(R.string.reminder_notification_list, task.getList().getName()));
    inboxStyle.addLine(context.getString(R.string.reminder_notification_priority, priority));
    inboxStyle.addLine(context.getString(R.string.reminder_notification_due, due));
    builder.setStyle(inboxStyle);
    // Build notification
    if (!allReminders.contains(task.getId())) {
        allReminders.add(task.getId());

        nm.notify(DefinitionsHelper.NOTIF_REMINDER + (int) task.getId(), builder.build());
    }
}

From source file:com.battlelancer.seriesguide.api.Action.java

/**
 * Serializes this {@link Action} object to a {@link android.os.Bundle} representation.
 *//* www .j av a 2  s .co  m*/
public Bundle toBundle() {
    Bundle bundle = new Bundle();
    bundle.putString(KEY_TITLE, mTitle);
    bundle.putString(KEY_VIEW_INTENT,
            (mViewIntent != null) ? mViewIntent.toUri(Intent.URI_INTENT_SCHEME) : null);
    bundle.putInt(KEY_ENTITY_IDENTIFIER, mEntityIdentifier);
    return bundle;
}

From source file:de.micmun.android.workdaystarget.DaysLeftService.java

/**
 * Updates the days to target./* ww  w . ja v a  2  s .co  m*/
 */
private void updateDays() {
    AppWidgetManager appManager = AppWidgetManager.getInstance(this);
    ComponentName cName = new ComponentName(getApplicationContext(), DaysLeftProvider.class);
    int[] appIds = appManager.getAppWidgetIds(cName);

    DayCalculator dayCalc = new DayCalculator();
    if (!isOnline()) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupted: " + e.getLocalizedMessage());
        }
    }

    for (int appId : appIds) {
        PrefManager pm = new PrefManager(this, appId);
        Calendar target = pm.getTarget();
        boolean[] chkDays = pm.getCheckedDays();
        int days = pm.getLastDiff();

        if (isOnline()) {
            try {
                days = dayCalc.getDaysLeft(target.getTime(), chkDays);
                Map<String, Object> saveMap = new HashMap<String, Object>();
                Long diff = Long.valueOf(days);
                saveMap.put(PrefManager.KEY_DIFF, diff);
                pm.save(saveMap);
            } catch (JSONException e) {
                Log.e(TAG, "ERROR holidays: " + e.getLocalizedMessage());
            }
        } else {
            Log.e(TAG, "No internet connection!");
        }
        RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.appwidget_layout);
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        String targetStr = df.format(target.getTime());
        rv.setTextViewText(R.id.target, targetStr);
        String dayStr = String.format(Locale.getDefault(), "%d %s", days,
                getResources().getString(R.string.unit));
        rv.setTextViewText(R.id.dayCount, dayStr);

        // put widget id into intent
        Intent configIntent = new Intent(this, ConfigActivity.class);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);
        configIntent.setData(Uri.parse(configIntent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent pendIntent = PendingIntent.getActivity(this, 0, configIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setOnClickPendingIntent(R.id.widgetLayout, pendIntent);

        // update widget
        appManager.updateAppWidget(appId, rv);
    }
}

From source file:io.v.example.vbeam.vbeamexample.MainActivity.java

@Override
public ListenableFuture<Pair<String, byte[]>> createIntent(VContext context, ServerCall call) {
    String blessing = "anonymous";
    String[] names = VSecurity.getRemoteBlessingNames(ctx, call.security());
    if (names.length > 0) {
        blessing = names[0];/* w  w  w .  j a v a  2  s . c o m*/
    }
    byte[] payload = ("Hello " + blessing).getBytes(Charset.forName("utf-8"));
    Intent intent = new Intent(this, GotBeamActivity.class);
    intent.setPackage(getApplicationContext().getPackageName());
    System.out.println("APP_SCHEME: " + intent.toUri(Intent.URI_ANDROID_APP_SCHEME));
    System.out.println("INTENT_SCHEME: " + intent.toUri(Intent.URI_INTENT_SCHEME));
    return Futures.immediateFuture(new Pair<>(intent.toUri(Intent.URI_INTENT_SCHEME), payload));
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

private RemoteViews buildLayout(Context context, int appWidgetId, boolean showProgress) {
    RemoteViews rv;/*from w w  w. ja v a 2  s.  c  o m*/
    // Specify the service to provide data for the collection widget. Note
    // that we need to
    // embed the appWidgetId via the data otherwise it will be ignored.
    final Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv = new RemoteViews(context.getPackageName(), R.layout.listwidget);
    rv.setRemoteAdapter(R.id.widget_list, intent);

    // Set the empty view to be displayed if the collection is empty. It
    // must be a sibling
    // view of the collection view.
    rv.setEmptyView(R.id.widget_list, R.id.empty_view);

    // Set click listener for the logo
    //        Intent clickIntent = new Intent(context, LoginScreen.class);
    //        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0);
    //        rv.setOnClickPendingIntent(R.id.listwidget_header, pendingIntent);

    // Set click listener for the 'add' button
    //        if (isAuthenticated(context)) {
    //            PendingIntent taskStackBuilderPendingIntent = TaskStackBuilder
    //                    .create(context)
    //                    .addNextIntent(new Intent(context, TodoTxtTouch.class))
    //                    .addNextIntent(new Intent(context, AddTask.class))
    //                    .getPendingIntent(0, 0);
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem,
    //                    taskStackBuilderPendingIntent);
    //        } else {
    //            // if not logged in, just go to login screen
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem, pendingIntent);
    //        }

    // Bind a click listener template for the contents of the list.
    // Note that we
    // need to update the intent's data if we set an extra, since the extras
    // will be
    // ignored otherwise.
    final Intent onClickIntent = new Intent(context, TodoTxtTouch.class);
    onClickIntent.setAction(ListWidgetProvider.ITEM_ACTION);
    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
    rv.setPendingIntentTemplate(R.id.widget_list, onClickPendingIntent);

    // Bind the click intent for the refresh button on the widget
    final Intent refreshIntent = new Intent(context, ListWidgetProvider.class);
    refreshIntent.setAction(ListWidgetProvider.REFRESH_ACTION);
    refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.listwidget_refresh, refreshPendingIntent);

    if (showProgress) {
        rv.setViewVisibility(R.id.listwidget_progress, View.VISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.listwidget_progress, View.INVISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.VISIBLE);
    }

    return rv;
}