Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

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

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

@SuppressWarnings("deprecation")
public void setServiceForeground(Context mContext) {
    final int myID = 9999;

    // The intent to launch when the user clicks the expanded notification
    Intent mIntent = new Intent(mContext, BackgroundActivity.class);
    mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0, mIntent, 0);

    // This constructor is deprecated. Use Notification.Builder instead
    Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name),
            System.currentTimeMillis());

    // This method is deprecated. Use Notification.Builder instead.
    mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification),
            pendIntent);//w w  w.ja v a  2s . c  o m

    mNotification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(myID, mNotification);
}

From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java

public void createDeskShortCut() {
    // ????/*w w  w. j a v  a  2 s .  c om*/
    SharedPreferenceUtil.editShortCut(true);
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClass(this, SplashActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    shortcutIntent.setAction("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");

    Intent resultIntent = new Intent();
    resultIntent.putExtra("duplicate", false);
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    resultIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
    resultIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
}

From source file:com.anykey.balala.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);// w w  w .jav  a2s  . co  m
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:fm.smart.r1.CreateExampleActivity.java

public void onClick(View v) {
    EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence);
    EditText translationInput = (EditText) findViewById(R.id.create_example_translation);
    EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration);
    EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration);
    final String example = exampleInput.getText().toString();
    final String translation = translationInput.getText().toString();
    if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) {
        Toast t = Toast.makeText(this, "Example and translation are required fields", 150);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();/*  w  ww .  ja  va  2s  .c  o  m*/
    } else {
        final String example_language_code = Utils.LANGUAGE_MAP.get(example_language);
        final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language);
        final String example_transliteration = exampleTransliterationInput.getText().toString();
        final String translation_transliteration = translationTransliterationInput.getText().toString();

        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
            // navigation
            // back to this?
            LoginActivity.return_to = CreateExampleActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("goal_id", goal_id);
            LoginActivity.params.put("item_id", item_id);
            LoginActivity.params.put("example", example);
            LoginActivity.params.put("translation", translation);
            LoginActivity.params.put("example_language", example_language);
            LoginActivity.params.put("translation_language", translation_language);
            LoginActivity.params.put("example_transliteration", example_transliteration);
            LoginActivity.params.put("translation_transliteration", translation_transliteration);
            startActivity(intent);
        } else {

            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Creating Example ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread create_example = new Thread() {
                public void run() {
                    // TODO make this interruptable .../*if
                    // (!this.isInterrupted())*/
                    try {
                        // TODO failures here could derail all ...
                        CreateExampleActivity.add_item_goal_result = new AddItemResult(
                                Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null));

                        Result result = null;
                        try {
                            result = Main.lookup.createExample(Main.transport, translation,
                                    translation_language_code, translation, null, null, null);
                            JSONObject json = new JSONObject(result.http_response);
                            String text = json.getString("text");
                            String translation_id = json.getString("id");
                            result = Main.lookup.createExample(Main.transport, example, example_language_code,
                                    example_transliteration, translation_id, item_id, goal_id);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        CreateExampleActivity.create_example_result = new CreateExampleResult(result);

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    myOtherProgressDialog.dismiss();

                }
            };
            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    create_example.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    create_example.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            myOtherProgressDialog.show();
            create_example.start();
        }
    }
}

From source file:com.mono.applink.Foursquare.java

/** Called when the activity is first created. */
@Override/* ww w .j  a v a 2s  .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("user"))//user with id
    {
        new FoursquareUser().execute();
    } else if (url.contains("venue")) {
        new FoursquareVenue().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

}

From source file:ablgroup.daily2.authentification.AuthentificationFragment.java

public void launchMainActivity() {
    Intent intent = new Intent(AuthentificationFragment.this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);/*from  ww w  .ja  va  2 s.co m*/
}

From source file:org.youaretheone.website.client.UoneSearchGsonActivity.java

private void checkTab() {
    if (mMenuPanel != null) {
        if (mMenuPanel.getVisibility() == View.VISIBLE) {
            toggleMenu();//from   w w w .  ja  va  2  s.  c o m
        }
        switch (mTabHost.getCurrentTab()) {
        case TabItem.SEARCH:
            content.setText(getString(R.string.search));
            (new UoneSearchTask()).execute();
            break;
        case TabItem.SHARE:
            content.setText(getString(R.string.share));
            (new UoneSearchTask()).execute();
            break;
        case TabItem.WEBSITE:
            content.setText(getString(R.string.website));
            final Intent visit = new Intent(Intent.ACTION_VIEW);
            visit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            visit.setData(android.net.Uri.parse(WEBSITE));

            // Use a thread so that the menu is responsive when
            // clicked
            new Thread(new Runnable() {
                public void run() {
                    startActivity(visit);
                }
            }).start();
            break;
        case TabItem.SETTINGS:
            content.setText(getString(R.string.settings));
            (new UoneSearchTask()).execute();
            break;
        case TabItem.QUIT:
            content.setText(getString(R.string.quit));
            new Thread(new Runnable() {
                public void run() {
                    UoneSearchGsonActivity.this.finish();

                    // The following makes the Android Gods frown
                    // upon me
                    android.os.Process.killProcess(android.os.Process.myPid());
                    System.exit(0);
                }
            }).start();
            break;
        default:
            break;
        }

        // Handle click on currently selected tab - hide menu bar
        // IMPORTANT: This listener has to appear AFTER the tabs are
        // added
        // Unfortunately, This doesn't work when the current tab
        // contains an activity (except for tab 0)
        // If you only have method tabs then it works perfect
        mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        toggleMenu();
                    }
                });

        // if you want to reset the current tab
        // mTabHost.setCurrentTab(0);
    }

}

From source file:com.mono.applink.Twitter.java

/** Called when the activity is first created. */
@Override/*from   w w  w .  j av a2s .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("twitter.com") && !url.contains("status") && !url.contains("direct_messages")
            && !url.contains("user_spam_reports") && !url.contains("account") && !url.contains("settings"))//Just if it is a link of a user profile
    {
        new TwitterUser().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.appnexus.opensdk.ANNativeAdResponse.java

boolean handleClick(String clickUrl, Context context) {
    if (clickUrl == null || clickUrl.isEmpty()) {
        return false;
    }/*  ww  w .j a  v a  2s.  com*/
    // if install, open store
    if (clickUrl.contains("://play.google.com") || clickUrl.contains("market://")) {
        Clog.d(Clog.nativeLogTag, Clog.getString(R.string.opening_app_store));
        return openNativeIntent(clickUrl, context);
    }
    // open browser
    if (openNativeBrowser) {
        // if set to use native browser, open intent
        if (openNativeIntent(clickUrl, context)) {
            if (listener != null) {
                listener.onAdWillLeaveApplication();
            }
            return true;
        }
        return false;
    } else {
        // launch Browser Activity
        Class<?> activity_clz = AdActivity.getActivityClass();
        try {
            WebView out = new WebView(new MutableContextWrapper(context));
            WebviewUtil.setWebViewSettings(out);
            out.loadUrl(clickUrl);
            BrowserAdActivity.BROWSER_QUEUE.add(out);

            Intent intent = new Intent(context, activity_clz);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_BROWSER);
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            Clog.w(Clog.baseLogTag, Clog.getString(R.string.adactivity_missing, activity_clz.getName()));
            BrowserAdActivity.BROWSER_QUEUE.remove();
        } catch (Exception e) {
            // Catches PackageManager$NameNotFoundException for webview
            Clog.e(Clog.baseLogTag, "Exception initializing the redirect webview: " + e.getMessage());
            return false;
        }

        return false;
    }
}

From source file:com.zxing.qrcode.decoding.CaptureActivityHandler.java

@Override
public void handleMessage(Message message) {
    switch (message.what) {
    case R.id.auto_focus:
        // Log.d(TAG, "Got auto-focus message");
        // When one auto focus pass finishes, start another. This is the
        // closest thing to
        // continuous AF. It does seem to hunt a bit, but I'm not sure what
        // else to do.
        if (state == State.PREVIEW) {
            CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        }/*  w  ww . j  a  v  a2  s.c  o  m*/
        break;
    case R.id.restart_preview:
        Log.d(TAG, "Got restart preview message");
        restartPreviewAndDecode();
        break;
    case R.id.decode_succeeded:
        Log.d(TAG, "Got decode succeeded message");
        state = State.SUCCESS;
        Bundle bundle = message.getData();
        Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
        final String str_result = ((Result) message.obj).getText();
        System.out.println("====str_result====" + str_result);
        String match = "^[0-9]{13}";
        boolean b = str_result.matches(match);
        // Toast.makeText(activity, ""+b, 1).show();
        // activity.handleDecode((Result) message.obj, barcode);
        if (b) {
            String url = RequestUrls.TIAOXING_CODE_URL.replace("[code]", str_result);
            FinalHttp fh = new FinalHttp();
            fh.get(url, new AjaxCallBack<Object>() {
                @Override
                public void onSuccess(Object t) {
                    // TODO Auto-generated method stub
                    super.onSuccess(t);
                    try {

                        System.out.println("===TIAOXING_CODE_URL====" + new JSONObject(t.toString()));
                        Intent tagIntent = new Intent(activity, TagdetialActivity.class);
                        tagIntent.putExtra("jsonStr", t.toString());
                        tagIntent.putExtra("barcodes", str_result);
                        tagIntent.putExtra("eid", eid);
                        tagIntent.putExtra("tag_ids", tag_ids);
                        activity.startActivity(tagIntent);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Throwable t, String strMsg) {
                    // TODO Auto-generated method stub
                    super.onFailure(t, strMsg);
                }
            });
        } else {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // //// intent.setPackage("com.tencent.mm");//
                intent.putExtra(Intent.EXTRA_SUBJECT, "share");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                // // 
                // intent.setData(Uri.parse("http://weixin.qq.com/r/o3w_sRvEMSVOhwrSnyCH"));
                intent.setData(Uri.parse(str_result));
                activity.startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(activity, R.string.no_wechat_rem, Toast.LENGTH_SHORT).show();
            }
        }

        break;
    case R.id.decode_failed:
        // We're decoding as fast as possible, so when one decode fails,
        // start another.
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
        break;
    case R.id.return_scan_result:
        Log.d(TAG, "Got return scan result message");
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
        break;
    }
}