Example usage for android.content Intent toUri

List of usage examples for android.content Intent toUri

Introduction

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

Prototype

public String toUri(@UriFlags int flags) 

Source Link

Document

Convert this Intent into a String holding a URI representation of it.

Usage

From source file:Main.java

private static void appendIntent(StringBuilder sb, Intent intent) {
    if (intent != null) {
        String uri = intent.toUri(Intent.URI_INTENT_SCHEME);
        String action = intent.getAction();
        append(sb, "intent", action, uri);
    } else {//from   w w  w. jav  a2s . c  o  m
        append(sb, (String) null);
    }
}

From source file:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//  ww  w.  j a  v a2s. c o  m
 */
private static void updateWidget(Context context, int appWidgetId) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId/*w  w w .j a  v  a  2  s  .  c  o m*/
 */
private static void updateWidget(Context context, int appWidgetId) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    //        }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

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

private static PendingIntent updateAlarm(final Context ctx, final Task task) {
    final Intent intent = new Intent(ctx, ReminderAlarm.class);
    intent.setAction(SHOW_TASK);// ww w .  jav a2  s  . c o  m
    intent.putExtra(EXTRA_ID, task.getId());
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    if ((pendingIntent == null) || !task.getReminder().isPresent()) {
        return null;
    }
    Log.v(TAG, "Set alarm for " + task.getName() + " on " + task.getReminder().get().getTimeInMillis());
    final Optional<Recurring> recurringReminder = task.getRecurringReminder();
    if (!recurringReminder.isPresent()) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, task.getReminder().get().getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, task.getReminder().get().getTimeInMillis(),
                recurringReminder.get().getInterval(), pendingIntent);
    }
    return pendingIntent;
}

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  .  ja v a 2  s. c  o  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:uk.co.ashtonbrsc.intentexplode.Explode.java

private static String getUri(Intent src) {
    return (src != null) ? src.toUri(Intent.URI_INTENT_SCHEME) : null;
}

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

private static void createNotification(final Context context, final Task task) {
    Log.w(TAG, task.getName());//from  w w w  . j  a v a2s.  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.mods.grx.settings.utils.Utils.java

public static String change_extra_value_in_uri_string(String uri, String extra_key, String new_value) {
    Intent intent;
    try {/*  w w  w  . j  a va  2 s .co m*/
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
        return null;
    }

    if (intent != null) {
        intent.putExtra(extra_key, new_value);
        return intent.toUri(0);
    }
    return null;
}

From source file:love.juhe.androidmonkey.MonkeyActivityEvent.java

@SuppressLint("NewApi")
@Override//from  w ww . ja v  a 2  s.  c  o  m
public int fireEvent(Instrumentation testRuner) {
    Intent intent = getEvent();
    MonkeyLog.l(":Switch: " + intent.toUri(0));

    if (mAlarmTime != 0) {
        Bundle args = new Bundle();
        args.putLong("alarmTime", mAlarmTime);
        intent.putExtras(args);
    }
    try {
        //         IntentFilter filter = new IntentFilter(getEvent().getAction());
        //         ActivityMonitor monitor = testRuner.addMonitor(filter, null, true);
        testRuner.startActivitySync(intent);
        //         testRuner.waitForMonitorWithTimeout(monitor, 10);

    } catch (SecurityException e) {
        MonkeyLog.l("** Permissions error starting activity " + intent.toUri(0));
        return MonkeyEvent.INJECT_ERROR_SECURITY_EXCEPTION;
    }
    return MonkeyEvent.INJECT_SUCCESS;
}

From source file:com.chen.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri,
        final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }//  www  .  ja  v  a 2 s.c om

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}