Example usage for android.content Intent addFlags

List of usage examples for android.content Intent addFlags

Introduction

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

Prototype

public @NonNull Intent addFlags(@Flags int flags) 

Source Link

Document

Add additional flags to the intent (or with existing flags value).

Usage

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

@Override
public void activate(Context context, SignedObj obj) {
    if (!(obj instanceof DbObj)) {
        Log.w(TAG, "Obj not ready yet!");
        return;/*from  w  w w .  j  a  va 2s . c o m*/
    }
    if (DBG) {
        JSONObject content = obj.getJson();
        Log.d(TAG, "activating app " + content + " from " + obj.getHash());
    }

    Intent launch = getLaunchIntent(context, (DbObj) obj);
    if (!(context instanceof Activity)) {
        launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    context.startActivity(launch);
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

/**
 * Handle export in the provided background thread
 *//*w  w w  .java  2  s. c o m*/
private void handleOsmExport(boolean includeAddress, boolean includeFixme) {
    //TODO handle empty survey
    //TODO handle bounds around +/-180

    if (!isExternalStorageWritable()) {
        notifyUserOfError();
        return;
    }

    int id = 0;
    double minLat = 200;
    double minLng = 200;
    double maxLat = -200;
    double maxLng = -200;
    StringBuilder builder = new StringBuilder();

    if (includeAddress) {
        Uri uri = AddressTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                AddressTableMetaData.LATITUDE, AddressTableMetaData.LONGITUDE, AddressTableMetaData.NUMBER,
                AddressTableMetaData.STREET }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(AddressTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(AddressTableMetaData.LONGITUDE);
            int iNumber = cursor.getColumnIndex(AddressTableMetaData.NUMBER);
            int iStreet = cursor.getColumnIndex(AddressTableMetaData.STREET);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String number = cursor.getString(iNumber);
                String street = cursor.getString(iStreet);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "addr:housenumber", number);
                addOsmTag(builder, "addr:street", street);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    if (includeFixme) {
        Uri uri = FixmeTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                FixmeTableMetaData.LATITUDE, FixmeTableMetaData.LONGITUDE, FixmeTableMetaData.COMMENT }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(FixmeTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(FixmeTableMetaData.LONGITUDE);
            int iComment = cursor.getColumnIndex(FixmeTableMetaData.COMMENT);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String comment = cursor.getString(iComment);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "fixme", comment);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    try {
        File destinationFile = getDestinationFile();
        destinationFile.getParentFile().mkdirs();
        PrintWriter writer = new PrintWriter(destinationFile, "UTF-8");

        writer.println("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
        writer.println("<osm version=\"0.6\" generator=\"OsmOnTheGo\">");
        writer.print("<bounds minlat=\"");
        writer.print(minLat - MARGIN);
        writer.print("\" minlon=\"");
        writer.print(minLng - MARGIN);
        writer.print("\" maxlat=\"");
        writer.print(maxLat + MARGIN);
        writer.print("\" maxlon=\"");
        writer.print(maxLng + MARGIN);
        writer.println("\" />");

        writer.println(builder);

        writer.print("</osm>");
        writer.close();

        if (writer.checkError()) {
            notifyUserOfError();
        } else {
            //FIXME i18n the subject and content
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.setType(HTTP.OCTET_STREAM_TYPE);
            //emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"johndoe@exemple.com"});
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OSM On The Go");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Your last survey.");
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile));
            startActivity(emailIntent);
        }
    } catch (IOException e) {
        Log.e(TAG, "Could not write to file", e);
        notifyUserOfError();
    }

}

From source file:android.security.cts.BrowserTest.java

/**
 * Create intents for all activities that can display the given URI.
 *//*  w ww . j  a va 2 s  .  c om*/
private List<Intent> createAllIntents(Uri uri) {

    Intent implicit = new Intent(Intent.ACTION_VIEW);
    implicit.setData(uri);

    /* convert our implicit Intent into multiple explicit Intents */
    List<Intent> retval = new ArrayList<Intent>();
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(implicit, PackageManager.GET_META_DATA);
    for (ResolveInfo i : list) {
        Intent explicit = new Intent(Intent.ACTION_VIEW);
        explicit.setClassName(i.activityInfo.packageName, i.activityInfo.name);
        explicit.setData(uri);
        explicit.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        retval.add(explicit);
    }

    return retval;
}

From source file:com.shopify.sample.activity.CheckoutActivity.java

private void launchBrowser(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.setData(Uri.parse(url));/*from ww w  .  ja  va 2 s.c o  m*/

    try {
        intent.setPackage("com.android.chrome");
        startActivity(intent);

    } catch (Exception launchChromeException) {
        try {
            // Chrome could not be opened, attempt to us other launcher
            intent.setPackage(null);
            startActivity(intent);

        } catch (Exception launchOtherException) {
            onError(getString(R.string.checkout_error));
        }
    }
}

From source file:com.kakao.kakaolink.KakaoLink.java

/**
 *  ? ??    .//  w w w  .  jav a2 s. co  m
 * @param builder     KakaoTalkLinkMessageBuilder
 * @param context ?  context
 * @throws KakaoParameterException ?   ?   ? ?
 */
public void sendMessage(final KakaoTalkLinkMessageBuilder builder, final Context context)
        throws KakaoParameterException {
    final Intent intent = TalkProtocol.createKakakoTalkLinkIntent(context, builder.build());
    if (intent == null) {
        //alert install dialog
        new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_dialog_alert)
                .setMessage(context.getString(R.string.com_kakao_alert_install_kakaotalk))
                .setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent marketIntent;
                        try {
                            marketIntent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(KakaoTalkLinkProtocol.TALK_MARKET_URL_PREFIX + makeReferrer()));
                            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(marketIntent);
                        } catch (ActivityNotFoundException e) {
                            marketIntent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(KakaoTalkLinkProtocol.TALK_MARKET_URL_PREFIX_2 + makeReferrer()));
                            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(marketIntent);
                        }
                    }
                }).create().show();

    } else {
        context.startActivity(intent);
    }
}

From source file:io.coldstart.android.GCMIntentService.java

private void SendCombinedNotification(String EventCount) {
    Notification notification = new Notification(R.drawable.ic_stat_alert, EventCount + " new SNMP Traps!",
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.ledARGB = 0xffff0000;/*from ww w.j  a v  a2s  .c o  m*/

    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;

    notification.defaults |= Notification.DEFAULT_SOUND;

    Context context = getApplicationContext();
    Intent notificationIntent = new Intent(this, TrapListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, EventCount + " SNMP Traps", "Click to launch ColdStart.io",
            contentIntent);
    mNM.notify(43523, notification);//NotificationID++ 
}

From source file:org.wso2.app.catalog.api.ApplicationManager.java

/**
 * Removes an application from the device.
 *
 * @param packageName - Application package name should be passed in as a String.
 *//*from  w  ww. j  av a2s  .  c  o  m*/
public void uninstallApplication(String packageName) {
    if (packageName != null
            && !packageName.contains(resources.getString(R.string.application_package_prefix))) {
        packageName = resources.getString(R.string.application_package_prefix) + packageName;
    }

    if (isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) {
        CommonUtils.callAgentApp(context, Constants.Operation.UNINSTALL_APPLICATION, packageName, null);
    } else {
        Uri packageURI = Uri.parse(packageName);
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
        uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(uninstallIntent);
    }
}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

/** Called when a session detail view asks to send session results somewhere. 
 * Generates a link to the session report Uri, and lets the remote program read from it. 
 * The {@link RhetologContentProvider} generates the result file on demand.
 * //from  w  w w  .  j a  v a  2s .co m
 * */

@Override
public void onSessionSend(Context context, Uri session) {

    // Send to the program selected by the chooser below.
    Intent sendSession = new Intent(Intent.ACTION_SEND);

    // Permit to read from Rhetolog URIs.
    sendSession.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    // Note type of send as report.
    sendSession.setType(RhetologContract.RHETOLOG_TYPE_SESSION_REPORT);

    sendSession.putExtra(Intent.EXTRA_SUBJECT, "Sending session " + session);

    // Send text as text.
    sendSession.putExtra(Intent.EXTRA_TEXT, reportForSession(session));

    // Send text as URI to be read.
    sendSession.putExtra(Intent.EXTRA_STREAM,
            Uri.parse(RhetologContract.SESSIONSREPORT + "/" + session.getLastPathSegment()));

    // Permit user to choose target of send.
    context.startActivity(Intent.createChooser(sendSession, "Send session results"));
}

From source file:net.mEmoZz.PopMovies.frags.DetailFragment.java

private Intent createShareForecastIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this movie: " + titleEndPoint + " from #Popular_Movies_APP");
    return shareIntent;
}

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

@Override
public void activate(Context context, SignedObj obj) {
    // TODO: set data uri for obj
    Intent intent = new Intent(context, ImageGalleryActivity.class);
    intent.setData(Feed.uriForName(obj.getFeedName()));
    intent.putExtra("objHash", obj.getHash());
    if (!(context instanceof Activity)) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }/*from ww  w .j  av a  2  s  .c o  m*/
    context.startActivity(intent);
}