Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

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

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:com.wso2.mobile.mdm.DisplayDeviceInfoActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && FROM_ACTIVITY != null
            && FROM_ACTIVITY.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
        Intent intent = new Intent(DisplayDeviceInfoActivity.this, AlreadyRegisteredActivity.class);
        intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
                DisplayDeviceInfoActivity.class.getSimpleName());
        intent.putExtra(getResources().getString(R.string.intent_extra_regid), REG_ID);
        startActivity(intent);/* ww  w . j  a  va2  s  . c o m*/
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        this.startActivity(i);
        this.finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.SearchableActivityTest.java

private void configureSearchIntent() {
    Intent launchIntent = new Intent();
    launchIntent.setAction(Intent.ACTION_SEARCH);
    Bundle extras = new Bundle();
    extras.putString(SearchableActivity_.QUERY_EXTRA, SEARCH_QUERY);
    launchIntent.putExtras(extras);//from  w w  w  . ja v a2 s .co  m
    setActivityIntent(launchIntent);
}

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

private void updateRemoteViews(Context context, RemoteViews views) {
    if (title != null) {
        views.setTextViewText(R.id.title, title);
    }//  w ww  .j  a  va  2  s .c om

    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));
}

From source file:com.openerp.services.MailGroupSyncService.java

public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {

    try {/*from   w  w w . jav a2s.  c  o m*/
        Intent intent = new Intent();
        intent.setAction(SyncFinishReceiver.SYNC_FINISH);

        MailGroupDB db = new MailGroupDB(context);
        db.setAccountUser(OpenERPAccountManager.getAccountDetail(context, account.name));
        OEHelper oe = db.getOEInstance();
        if (oe != null && oe.syncWithServer(true)) {
            MailFollowers followers = new MailFollowers(context);

            OEDomain domain = new OEDomain();
            domain.add("partner_id", "=", oe.getUser().getPartner_id());
            domain.add("res_model", "=", db.getModelName());

            if (followers.getOEInstance().syncWithServer(domain, true)) {
                // syncing group messages
                JSONArray group_ids = new JSONArray();
                for (OEDataRow grp : followers.select("res_model = ? AND partner_id = ?",
                        new String[] { db.getModelName(), oe.getUser().getPartner_id() + "" })) {
                    group_ids.put(grp.getInt("res_id"));
                }
                Bundle messageBundle = new Bundle();
                messageBundle.putString("group_ids", group_ids.toString());
                messageBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                messageBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                ContentResolver.requestSync(account, MessageProvider.AUTHORITY, messageBundle);

            }
        }
        if (OpenERPAccountManager.currentUser(context).getAndroidName().equals(account.name))
            context.sendBroadcast(intent);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.galois.qrstream.lib.DecodeThread.java

private Intent buildIntent(Job message) throws IOException {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_SEND);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    String mimeType = message.getMimeType();
    i.setType(mimeType);/*from www .j av a  2s . c  om*/

    if (mimeType.equals("text/plain")) {
        String msg = new String(message.getData());
        i.putExtra(Intent.EXTRA_TEXT, msg);
    } else {
        // content that is not text uses the filesystem to store the data
        // (when sharing with a new local app)
        File dataLoc = storeData(message);

        if (mimeType.startsWith("image/")) {
            String path = Images.Media.insertImage(context.getContentResolver(), dataLoc.getPath(),
                    message.getTitle(), null);
            Uri imageUri = Uri.parse(path);
            i.putExtra(Intent.EXTRA_STREAM, imageUri);

            // we can delete the temporary location in this case, since the file has been saved
            // to the media store.
            // In the other cases, the receiver has to handle the content of the temp file before
            // it can be deleted -- but we will never know if/when that happens.
            dataLoc.delete();
        } else if (mimeType.equals(Constants.MIME_TYPE_TEXT_NOTE)) {
            String json = new String(message.getData());
            try {
                JSONObject note = new JSONObject(json);
                i.putExtra(Intent.EXTRA_TEXT, note.getString(Intent.EXTRA_TEXT));
                i.putExtra(Intent.EXTRA_SUBJECT, note.getString(Intent.EXTRA_SUBJECT));
                i.setType("text/plain");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            i.putExtra(Intent.EXTRA_STREAM, dataLoc.toURI());
        }
    }
    return i;
}

From source file:com.google.developers.actions.debugger.CayleyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {/*from  w w  w  . j  a  v a  2s.c om*/
        getActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    setContentView(R.layout.activity_cayley);
    Intent intent = getIntent();
    intent.setAction(intent.getStringExtra(MainActivity.ACTION));
    intent.setComponent(null);
    mIntent = intent;
    mActionType = intent.getStringExtra(MainActivity.ACTION_TYPE);
    if (mActionType.equals("PLAY_ARTIST")) {
        mEditText = (EditText) findViewById(R.id.artist);
        mEditText.setVisibility(View.VISIBLE);
        mEditText.setText(getString(R.string.dual_core));
    } else {
        mEditText = (EditText) findViewById(R.id.genre);
        mEditText.setVisibility(View.VISIBLE);
        mEditText.setText(getString(R.string.nerdcore));
    }
}

From source file:com.openerp.services.ContactSyncService.java

public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    try {/*from ww w . ja  v a  2 s .com*/
        Intent intent = new Intent();
        intent.setAction(SyncFinishReceiver.SYNC_FINISH);

        String saasURL1 = "https://openerp.my.openerp.com";
        String saasURL2 = "https://accounts.openerp.com";
        Res_PartnerDBHelper db = new Res_PartnerDBHelper(context);
        OEHelper oe = db.getOEInstance();
        Res_PartnerSyncHelper helper = new Res_PartnerSyncHelper(context);

        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        boolean syncServerContacts = settings.getBoolean("server_contact_sync", false);

        if (OpenERPAccountManager.currentUser(context).getHost().toString().contains(saasURL1)
                || OpenERPAccountManager.currentUser(context).getHost().toString().contains(saasURL2)) {
            helper.syncContacts(context, account);

        } else {
            if (syncServerContacts) {
                int company_id = Integer.parseInt(OpenERPAccountManager.currentUser(context).getCompany_id());

                JSONObject domain = new JSONObject();
                domain.accumulate("domain", new JSONArray("[[\"company_id\", \"=\", " + company_id + "]]"));
                if (oe.syncWithServer(db, domain, false)) {
                    helper.syncContacts(context, account);
                }
            } else {
                helper.syncContacts(context, account);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String mimeType = obj.optString(MIME_TYPE);
    Uri uri = Uri.parse(obj.optString(URI));
    if (fileAvailable(mimeType, uri)) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setType(mimeType);/*from  www.  ja  v a 2  s  .  c  o  m*/
        i.setData(uri);
        i.putExtra(Intent.EXTRA_TEXT, uri);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i,
                PendingIntent.FLAG_CANCEL_CURRENT);
        (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi",
                mimeType + "  " + uri, contentIntent);
    } else {
        Log.w(TAG, "Received file, failed to handle: " + uri);
    }
}

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

/** Called when the activity is first created. */
@Override/*from ww  w . j  a  v a 2 s.co m*/
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:com.mono.applink.Twitter.java

/** Called when the activity is first created. */
@Override//ww w .j av a2  s  . 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();
    }
}