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: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 . ja  va  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.android.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final int folderCapabilities, 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_CAPABILITIES, folderCapabilities);
    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);
    mailIntent.setPackage(context.getPackageName());
    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.setPackage(context.getPackageName());
    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);
    }/*  ww  w. j ava  2 s  . com*/

    // 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.setPackage(context.getPackageName());
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

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

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final int folderCapabilities, 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_CAPABILITIES, folderCapabilities);
    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);
    remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 ADD
    // 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);
    //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_S
    composeIntent.setPackage(context.getPackageName());
    //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_E
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_WIDGET, true); //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }//from   w  ww.java 2  s  .  com

    // 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);
}

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

private RemoteViews buildLayout(Context context, int appWidgetId, boolean showProgress) {
    RemoteViews rv;/*from  w  w  w. j a  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;
}

From source file:com.appsimobile.appsihomeplugins.dashclock.configuration.AppChooserPreference.java

public void setIntentValue(Intent intent) {
    setValue(intent == null ? "" : intent.toUri(Intent.URI_INTENT_SCHEME));
}

From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d(LOG_TAG, context.getString(R.string.log_on_update));

    // Update each app widget instance with remote view and corresponding remote adapter.
    for (int appWidgetId : appWidgetIds) {
        // Create the remote views object for the widget instance.
        RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_news);

        // Create the intent that starts the service which will provide the views for this collection.
        Intent serviceIntent = new Intent(context, NewsWidgetRemoteViewsService.class);

        // Add the app widget id to the intent extras.
        serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the remote adapter onto the scores list view in the remote view.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            remoteView.setRemoteAdapter(R.id.widget_list_view, serviceIntent);
        } else {/*from w w w  .j  a va  2 s  .co  m*/
            remoteView.setRemoteAdapter(appWidgetId, R.id.widget_list_view, serviceIntent);
        }

        // Create an intent to launch the main activity and set it on the remote view's title.
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        remoteView.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Create and add the list item click pending intent template.
        Intent listItemClickIntent = new Intent(context, MainActivity.class);
        listItemClickIntent.setAction(context.getString(R.string.action_item_clicked))
                .setData(Uri.parse(listItemClickIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the pending intent template.
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(listItemClickIntent)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteView.setPendingIntentTemplate(R.id.widget_list_view, clickPendingIntentTemplate);

        // Set an empty view in case of no data.
        remoteView.setEmptyView(R.id.widget_list_view, R.id.widget_empty);

        // Call app widget manager to update the app widget instance.
        appWidgetManager.updateAppWidget(appWidgetId, remoteView);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode != ICB_HOST_REQUEST_CODE) {
        return;/*from w  w w. j  av  a  2s  . c  om*/
    }

    Preferences prefs = new Preferences(this);

    if (data == null || resultCode != Activity.RESULT_OK) {
        prefs.setIcbHost(null, null);
    } else {
        String hostName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
        Intent intent = (Intent) data.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT);
        if (intent != null) {
            String intentUri = intent.toUri(0);
            prefs.setIcbHost(hostName, intentUri);
        } else {
            prefs.setIcbHost(null, null);
        }
    }

    handleIcb();
}

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

/**
 * Updates the Notification/*from w  ww .j a v  a 2 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:de.micmun.android.workdaystarget.DaysLeftService.java

/**
 * Updates the days to target.//from  www. jav  a 2  s.  com
 */
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:cc.flydev.launcher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from   w ww .  jav a  2 s  .  co m*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}