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: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. ja  v  a  2  s .c  o m*/
        append(sb, (String) null);
    }
}

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 {/* ww w . j  a v a  2 s.  c  o 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:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//from w  ww  .  jav  a2 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.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.appsimobile.appsihomeplugins.dashclock.configuration.AppChooserPreference.java

public static Intent getIntentValue(String value, Intent defaultIntent) {
    try {/*from   w  w  w  . j a v a2  s  . c  o m*/
        if (TextUtils.isEmpty(value)) {
            return defaultIntent;
        }

        return Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return defaultIntent;
    }
}

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

/**
 * Update the widget appWidgetId//  w  ww. j a va 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:com.eternizedlab.lunarcalendar.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default_title);
    }/*from   ww  w. j  a  v a  2 s.c  o m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default_title);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.ctrlplusz.dashclock.yr.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }//from   w w w  .  jav  a2s . com

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.google.android.apps.dashclock.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }/*from  ww w  .j av  a  2s  .  c o m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.isEmpty()) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

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

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }/*from  www  . ja  va2  s  . c  o  m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

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

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