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:com.llf.android.launcher3.InstallShortcutReceiver.java

@Override
public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from  ww  w.  j  a  va2 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);
    }
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from   w w  w .  j a v 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);
    }
}

From source file:com.telepromptu.TeleprompterService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, intent.toUri(0));
    if (mLiveCard == null) {
        Log.d(TAG, "Publishing LiveCard");
        mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);

        // Keep track of the callback to remove it before unpublishing.
        mCallback = new TeleprompterDrawer(this);
        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);

        Intent menuIntent = new Intent(this, MenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        mLiveCard.publish(PublishMode.REVEAL);
        Log.d(TAG, "Done publishing LiveCard");
    } else {//  w w w.  j  av a 2 s .  c  o m
        // TODO(alainv): Jump to the LiveCard when API is available.
    }

    (new Thread(new Runnable() {

        @Override
        public void run() {
            //            String text = "Hi! My name is Waseem Ahmad! I'm a senior studying computer science at Rice University. Today, I'm going to demonstrate an application that my team has created called Telepromptu. It is a Google Glass application that serves as a live automatic teleprompter. The application uses speech recognition to get snippets of text from Google Speech recognition API. Because the speech to text recognition is not fully accurate, our application uses a local subsequence alignment algorithm to match the recognized text with text on the teleprompter.";
            slides = connect("http://telepromptu.appspot.com/glass?id=" + presentationId);
            String text = "";
            for (Slide slide : slides) {
                text += slide.notes + " ";
            }
            mCallback.mTeleprompterView.setText(text);
            speechTraverser = new SuperSpeechTraverser(text);
        }

    })).start();

    startListening();

    return START_STICKY;
}

From source file:com.android.launcher4.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//ww  w.  j av a2 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 = ensureValidName(context, intent, data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME)).toString();
    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);
    }
}

From source file:com.android.launcher3.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from  ww  w. ja va  2s .  c om
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));
    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context);

    queuePendingShortcutInfo(info, context);
}

From source file:MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_RESULT && resultCode == RESULT_OK) {
        ImageView imageView = (ImageView) findViewById(R.id.imageView);
        imageView.setImageBitmap(BitmapFactory.decodeFile(mLastPhotoURI.getPath()));

        if (data != null) {
            imageView.setImageBitmap((Bitmap) data.getExtras().get("data"));

            try {
                imageView.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(),
                        Uri.parse(data.toUri(Intent.URI_ALLOW_UNSAFE))));
            } catch (IOException e) {
                e.printStackTrace();//from www  . j av a 2  s . c o m
            }
        }

    }
}

From source file:de.azapps.mirakel.sync.taskwarrior.services.SyncAdapter.java

/**
 * Shows the Notification with the error message if needed
 *
 * @param showNotification//www  .  j ava 2s  . com
 * @param success
 * @throws ClassNotFoundException
 */
private void handleError(final boolean showNotification, final boolean success) throws ClassNotFoundException {
    if (showNotification && !success) {
        final String title = "Mirakel: " + this.mContext.getText(R.string.finish_sync);
        final Intent openIntent = new Intent(this.mContext,
                Class.forName(DefinitionsHelper.MAINACTIVITY_CLASS));
        openIntent.setAction(DefinitionsHelper.SHOW_MESSAGE);
        openIntent.putExtra(Intent.EXTRA_SUBJECT, title);
        openIntent.putExtra(Intent.EXTRA_TEXT, last_message);
        openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME)));
        final PendingIntent pOpenIntent = PendingIntent.getActivity(this.mContext, 0, openIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        final Notification notification = new NotificationCompat.Builder(this.mContext).setContentTitle(title)
                .setContentText(last_message).setSmallIcon(android.R.drawable.stat_notify_sync)
                .setPriority(NotificationCompat.PRIORITY_LOW).setContentIntent(pOpenIntent).build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        this.mNotificationManager.notify(SyncAdapter.NOTIFY_ID, notification);
    }
}

From source file:com.android.messaging.ui.UIIntentsImpl.java

@Override
public PendingIntent getWidgetPendingIntentForConfigurationActivity(final Context context,
        final int appWidgetId) {
    final Intent configureIntent = new Intent(context, WidgetPickConversationActivity.class);
    configureIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    configureIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
    configureIntent.setData(Uri.parse(configureIntent.toUri(Intent.URI_INTENT_SCHEME)));
    configureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    return getPendingIntentWithParentStack(context, configureIntent, 0);
}

From source file:com.android.purenexussettings.TinkerActivity.java

@Override
protected void onActivityResult(int paramRequest, int paramResult, Intent paramData) {
    super.onActivityResult(paramRequest, paramResult, paramData);
    if (paramResult != -1 || paramData == null) {
        return;// w w  w .j a  va 2  s . c  om
    }
    switch (paramRequest) {
    case REQUEST_CREATE_SHORTCUT:
        Intent localIntent = paramData.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        localIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, paramData.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));

        String keystring = localIntent.toUri(0).replaceAll("com.android.contacts.action.QUICK_CONTACT",
                Intent.ACTION_VIEW);

        Settings.Global.putString(getContentResolver(), TinkerActivity.mPrefKey, keystring);
        onBackPressed();

        return;
    default:
    }
}

From source file:com.gh4a.BaseActivity.java

protected void saveBookmark(String name, int type, Intent intent, String extraData) {
    ContentValues cv = new ContentValues();
    cv.put(BookmarksProvider.Columns.NAME, name);
    cv.put(BookmarksProvider.Columns.TYPE, type);
    cv.put(BookmarksProvider.Columns.URI, intent.toUri(0));
    cv.put(BookmarksProvider.Columns.EXTRA, extraData);
    if (getContentResolver().insert(BookmarksProvider.Columns.CONTENT_URI, cv) != null) {
        Toast.makeText(this, R.string.bookmark_saved, Toast.LENGTH_LONG).show();
    }/*from w  w  w  .  j a va 2 s .co  m*/
}