Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:com.cordova.plugins.startapp.StartApp.java

/**
 * Starts an activity.//from  w  ww .j av  a2 s  .c om
 *
 * @param component
 *            Activity ComponentName.
 *            E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity
 */
void startActivity(String component) {
    try {
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        intent.setComponent(ComponentName.unflattenFromString(component));
        ((DroidGap) this.cordova.getActivity()).startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        /**
         * If not installed, open market
         */
        String[] packageNameSplt = component.split("/");
        String packageName = packageNameSplt[0];

        Intent marketIntent = new Intent(Intent.ACTION_VIEW);
        marketIntent.setData(Uri.parse("market://details?id=" + packageName));
        ((DroidGap) this.cordova.getActivity()).startActivity(marketIntent);
    }
}

From source file:co.uk.gauntface.mobile.devicelab.receiver.PushNotificationReceiver.java

private void launchBrowserTask(Context context, String url, String packageName) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setPackage(packageName);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1);
    if (activitiesList.size() > 0) {
        context.startActivity(browserIntent);
    } else {//from w  ww .jav  a  2 s.  c o m
        Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
        playStoreIntent.setData(Uri.parse("market://details?id=" + packageName));
        playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(playStoreIntent);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java

@Override
public void activate(Context context, SignedObj obj) {
    JSONObject content = obj.getJson();/*  w w  w  . j  a  v  a  2 s .  co m*/
    String groupName = content.optString(GROUP_NAME);
    Uri dynUpdateUri = Uri.parse(content.optString(DYN_UPDATE_URI));

    Intent launch = new Intent(Intent.ACTION_VIEW);
    launch.setData(dynUpdateUri);
    launch.putExtra("type", TYPE);
    launch.putExtra("creator", false);
    launch.putExtra(GROUP_NAME, groupName);
    launch.putExtra(DYN_UPDATE_URI, dynUpdateUri);
    context.startActivity(launch);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {//from ww  w. j ava  2s . c  o m
        String groupName = obj.getString(GROUP_NAME);
        Uri dynUpdateUri = Uri.parse(obj.getString(DYN_UPDATE_URI));

        Intent launch = new Intent(Intent.ACTION_VIEW);
        launch.setData(dynUpdateUri);
        launch.putExtra("type", TYPE);
        launch.putExtra("creator", false);
        launch.putExtra(SENDER, from.id);
        launch.putExtra(GROUP_NAME, groupName);
        launch.putExtra(DYN_UPDATE_URI, dynUpdateUri);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("Invitation from " + from.name,
                "Invitation from " + from.name, "Join the group '" + groupName + "'.", contentIntent);

    } catch (JSONException e) {
        Log.e(TAG, "Error handling message: ", e);
    }
}

From source file:br.com.brunogrossi.MediaScannerPlugin.MediaScannerPlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {//from   ww w  . j  a v a  2  s. com
        if (action.equals("scanFile")) {
            String fileUri = args.optString(0);
            if (fileUri != null && !fileUri.equals("")) {
                Uri contentUri = Uri.parse(fileUri);

                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                mediaScanIntent.setData(contentUri);
                this.cordova.getActivity().sendBroadcast(mediaScanIntent);

                callbackContext.success();

                return true;
            } else {
                Log.w(TAG, "No action param provided: " + action);
                callbackContext.error("No action param provided: " + action);
                return false;
            }
        } else {
            Log.w(TAG, "Wrong action was provided: " + action);
            return false;
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        callbackContext.error(e.getMessage());
        return false;
    }
}

From source file:com.zjut.material_wecenter.controller.fragment.SettingsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // ?/*from   ww  w .ja v a 2s  .co  m*/
    Preference version = findPreference("version");
    version.setSummary(BuildConfig.VERSION_NAME);
    // GitHub?
    Preference github = findPreference("github");
    github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(getString(R.string.github_url)));
            startActivity(intent);
            return false;
        }
    });
    // 
    new CheckForUpdate().execute();
}

From source file:com.axinom.drm.quickstart.activity.SampleChooserActivity.java

private void startVideoActivity(int position) {
    Intent intent = new Intent(this, PlayerActivity.class);
    intent.setData(Uri.parse(mVideoUrls.get(position)));
    intent.putExtra(PlayerActivity.LICENSE_TOKEN, mLicenseToken);
    intent.putExtra(PlayerActivity.WIDEVINE_LICENSE_SERVER, WIDEVINE_LICENSE_SERVER);
    startActivity(intent);//from ww  w  .j a va 2s  .  c  o m
}

From source file:co.uk.gauntface.cordova.plugin.gcmbrowserlaunch.PushNotificationReceiver.java

private void launchBrowserTask(Context context, String url, String packageName) {
    Log.v(C.TAG, "launchBrowserTask");
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setPackage(packageName);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1);
    if (activitiesList.size() > 0) {
        browserIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(browserIntent);
    } else {/* www  .  j av  a2  s  .c o m*/
        Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
        playStoreIntent.setData(Uri.parse("market://details?id=" + packageName));
        playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(playStoreIntent);
        /**Intent rawIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        rawIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(rawIntent);**/
    }
}

From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java

private void updateRemoteViews(Context context, RemoteViews views) {
    if (title != null) {
        views.setTextViewText(R.id.title, title);
    }//  www  .  j  a  v  a  2  s .c  o  m

    if (image != null) {
        views.setImageViewBitmap(R.id.image, image);
    } else {
        views.setImageViewBitmap(R.id.image, null);
    }

    Intent goToSiteIntent = new Intent(Intent.ACTION_VIEW);
    goToSiteIntent.setData(Uri.parse("http://xkcd.com"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, goToSiteIntent, 0);
    views.setOnClickPendingIntent(R.id.image, pendingIntent);

    if (altText != null) {
        views.setTextViewText(R.id.alt_text, altText);
    }

    Intent intent = new Intent(context, getClass());
    intent.setAction(UPDATE);
    views.setOnClickPendingIntent(R.id.sync, PendingIntent.getBroadcast(context, 0, intent, 0));
}