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:me.piebridge.prevent.ui.UserGuideActivity.java

private void retrieveInfo() {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    intent.setAction(PreventIntent.ACTION_GET_INFO);
    intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
    UILog.i("sending get info broadcast");
    if (receiver == null) {
        receiver = new HookReceiver();
    }//ww w  .  ja va2s  .com
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, null, 0, null, null);
}

From source file:ca.mcgill.hs.serv.LogFileUploaderService.java

/**
 * Runs a new thread that uploads all files in the fileList.
 *///  w w w.  j av  a2s  .  c om
private void uploadFiles() {
    new Thread() {
        @Override
        public void run() {
            updateFileList();
            String ff = null;
            while (!fileList.isEmpty()) {
                if (canUpload()) {
                    final String f = fileList.remove();
                    final int retCode = uploadFile(f);
                    if (retCode != NO_ERROR_CODE) {
                        // If the file is missing, or there is some problem
                        // reading the file, then the file is skipped.
                        // Otherwise it is put back into the queue.
                        if (retCode != UPLOAD_FAILED_FILE_NOT_FOUND_ERROR_CODE
                                && retCode != IOEXCEPTION_ERROR_CODE) {
                            fileList.addLast(f);
                            if (ff == null) {
                                ff = f;
                            } else {
                                // If we have gone through the whole list
                                // and all files are giving errors, if on
                                // automatic set the timer to try again,
                                // else break and alert user that there were
                                // errors.
                                if (ff.equals(f)) {
                                    if (automatic) {
                                        waiting = true;
                                        // We are waiting to try the upload
                                        // for this file again after a set
                                        // time.
                                        timerStart();
                                        return;
                                    } else {
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        // If there was no error code, the file was
                        // successfully uploaded.
                        filesUploaded++;
                    }
                } else {
                    if (automatic) {
                        waiting = true;
                        // We now wait for a connection to become available,
                        // so register a receiver for it.
                        registerReceiver(connectReceiver,
                                new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
                        connectionReceiverRegistered = true;
                        return;
                    } else {
                        CURRENT_ERROR_CODE = NO_CONNECTION_ERROR;
                        break;
                    }
                }
            }
            fileMap.clear();
            fileList.clear();
            if (httpclient != null) {
                httpclient.getConnectionManager().shutdown();
            }
            final Intent i = new Intent();
            i.setAction(UPLOAD_COMPLETE_INTENT);
            sendBroadcast(i);
        }
    }.start();
}

From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Override default Android "up" behavior to instead mimic the back button
        getActivity().onBackPressed();//from  ww w  . j  a v  a 2  s .  c o m
        return true;

    // Edit button
    case R.id.action_edit:
        Bundle bundle = new Bundle();
        bundle.putString("filename", filename);

        Fragment fragment = new NoteEditFragment();
        fragment.setArguments(bundle);

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                .commit();

        return true;

    // Delete button
    case R.id.action_delete:
        listener.showDeleteDialog();
        return true;

    // Share menu item
    case R.id.action_share:
        // Send a share intent
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad);
        intent.setType("text/plain");

        // Verify that the intent will resolve to an activity, and send
        if (intent.resolveActivity(getActivity().getPackageManager()) != null)
            startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));

        return true;

    // Export menu item
    case R.id.action_export:
        listener.exportNote(filename);
        return true;

    // Print menu item
    case R.id.action_print:
        listener.printNote(contentsOnLoad);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:uk.bowdlerize.service.CensorCensusService.java

private void warnOnError() {
    mBuilder.setStyle(new NotificationCompat.InboxStyle()
            .setBigContentTitle(getString(R.string.notifTitle) + " - No URLs")
            .addLine(getString(R.string.notifNoURLToCheck)).addLine(getString(R.string.notifAddURL))
            .setSummaryText(Integer.toString(checkedCount) + " " + getString(R.string.notifChecked) + " / "
                    + Integer.toString(censoredCount) + " " + getString(R.string.notifPossBlock)))
            .setSmallIcon(R.drawable.ic_stat_waiting)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_ooni_large))
            .setPriority(Notification.PRIORITY_MAX).setTicker(getString(R.string.notifTitle) + " - No URLs")
            .setAutoCancel(false);// ww  w .  j a v  a2 s. c  om
    mBuilder.setProgress(0, 0, false);

    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

    Intent newIntent = new Intent();
    newIntent.setAction(ProgressFragment.ORG_BROADCAST);
    newIntent.putExtra(ProgressFragment.ORG_BROADCAST, ProgressFragment.NO_URLS);
    sendBroadcast(newIntent);
}

From source file:com.dwdesign.tweetings.app.TweetingsApplication.java

public void getSync(String timeline, long account_id, String screen_name) {
    final SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final String username = screen_name;
    final String syncTimeline = timeline;
    if (preferences.getBoolean(PREFERENCE_KEY_SYNC_ENABLED, false)) {
        Runnable runnable = new Runnable() {
            @Override//from   ww  w. jav  a  2 s.com
            public void run() {
                String syncUrl = "";
                try {
                    if (preferences.getString(PREFERENCE_KEY_SYNC_TYPE, "tweetmarker").equals("tweetmarker")) {

                        syncUrl = "https://api.tweetmarker.net/v1/lastread?collection=" + syncTimeline
                                + "&username=" + username + "&api_key=" + TWEETMARKER_API_KEY;
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse response = httpClient.execute(new HttpGet(syncUrl));

                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                        String sResponse;
                        StringBuilder s = new StringBuilder();

                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
                        //Log.i("TweetMarker Retrieve", syncTimeline + " " + s.toString());

                        Intent broadcast = new Intent();
                        broadcast.putExtra(PARAM_SYNC_TYPE, syncTimeline);
                        broadcast.putExtra(PARAM_SYNC_ID, s.toString());

                        broadcast.setAction(BROADCAST_SYNC_ACTION);
                        sendBroadcast(broadcast);

                    } else {
                        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

                        syncUrl = TWEETINGS_SYNC_GET_URL + "?did=" + deviceId + "&android=1&u=" + username
                                + "&tl=" + syncTimeline;
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse response = httpClient.execute(new HttpGet(syncUrl));

                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                        String sResponse;
                        StringBuilder s = new StringBuilder();

                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
                        //Log.i("Tweetings Sync Retrieve", syncUrl + syncTimeline + " " + s.toString());

                        Intent broadcast = new Intent();
                        broadcast.putExtra(PARAM_SYNC_TYPE, syncTimeline);
                        broadcast.putExtra(PARAM_SYNC_ID, s.toString());

                        broadcast.setAction(BROADCAST_SYNC_ACTION);
                        sendBroadcast(broadcast);
                    }
                } catch (Exception e) {
                    Log.e("Sync", e.getMessage());
                    //Toast.makeText(getApplicationContext(), "Network exception" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        };
        new Thread(runnable).start();
    }
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false);

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice);
    lv = (ListView) rootView.findViewById(R.id.list);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
    lvItems = (ListView) rootView.findViewById(R.id.lvItems);

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override//from ww  w .j a v a2  s.c  o m
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input);
            edit_title.setHint(R.string.title_hint);

            final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input);
            edit_cont.setHint(R.string.text_hint);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTitle = edit_title.getText().toString().trim();
                    String inputCont = edit_cont.getText().toString().trim();

                    if (db.isExist(inputTitle)) {
                        Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
                    } else {
                        db.insert(inputTitle, inputCont, "", "", helper_main.createDate());
                        dialog.dismiss();
                        setRandomList();
                        Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show();
                    }
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_random");
            startActivity(mainIntent);
        }
    });

    fab_dice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            try {
                Random rand = new Random();
                final int n = rand.nextInt(lvItems.getCount());

                setAdapter(n);
                lvItems.setSelection(n - 1);

            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
    });

    //calling Notes_DbAdapter
    db = new Random_DbAdapter(getActivity());
    db.open();

    setRandomList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:net.gerosyab.dailylog.activity.MainActivity.java

private void exportCategory(final long id) {

    //?? ? ?? csv  
    //? ?? ?? //  w  w  w.  jav  a2 s . c  o  m
    // ? ?  ? ? 
    Category category = categories.get((int) id);

    ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setTitle("Exporting data [" + category.getName() + "]");
    progressDialog.show();

    String filename = category.getName() + "" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
            + ".data";
    FileOutputStream outputStream = null;
    File resultFilePath = null;
    File resultFile = null;
    CSVWriter cw = null;

    try {
        resultFile = new File(context.getCacheDir(), filename);

        outputStream = new FileOutputStream(resultFile.getAbsolutePath());
        //            cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"),'\t', '"');
        cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"), ',', '"');

        // Export Data
        String[] metaDataStr = { "Version:" + AppDatabase.VERSION, "Name:" + category.getName(),
                "Unit:" + category.getUnit(), "Type:" + category.getRecordType(),
                "DefaultValue:" + category.getDefaultValue(),
                "Columns:date(yyyy-MM-dd 24HH:mm:ss)/value(boolean|numeric|string)" };
        cw.writeNext(metaDataStr);

        List<Record> records = category.getRecordsOrderByDateAscending(realm);
        for (Record record : records) {
            String value = null;
            if (category.getRecordType() == StaticData.RECORD_TYPE_BOOLEAN) {
                value = "true";
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_NUMBER) {
                value = "" + record.getNumber();
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_MEMO) {
                value = record.getString();
            }
            String[] s = { record.getDateString(StaticData.fmtForBackup), value };
            cw.writeNext(s);
        }

        cw.close();
        outputStream.close();

        progressDialog.dismiss();

        Uri fileUri = FileProvider.getUriForFile(context, "net.gerosyab.dailylog.fileprovider", resultFile);

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
        shareIntent.setType("text/plain");

        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

    } catch (UnsupportedEncodingException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (Exception e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } finally {
        progressDialog.dismiss();
    }
}

From source file:uk.bowdlerize.service.CensorCensusService.java

private void prepProbe(final Intent intent) {
    Intent newIntent = new Intent();
    newIntent.setAction(ProgressFragment.ORG_BROADCAST);
    newIntent.putExtra(ProgressFragment.ORG_BROADCAST, ProgressFragment.TALKING_TO_ORG);
    sendBroadcast(newIntent);/*from  w w  w  .  jav a 2 s  .  c  o  m*/

    new Thread() {
        public void run() {
            String url;
            String hash;
            try {
                warnOnPrep();
                url = api.getURLBasic();
                hash = MD5(url);
                if (null == url) {
                    throw new NullPointerException("No URL");
                } else {
                    intent.putExtra("url", url);
                    intent.putExtra("hash", hash);
                    performProbe(intent);
                }
            } catch (Exception e) {
                e.printStackTrace();
                url = null;
                hash = ".....";
                warnOnError();
                onProbeFinish();
            }

        }
    }.start();
}

From source file:com.money.manager.ex.sync.SyncManager.java

private PendingIntent getPendingIntentForDelayedUpload() {
    DatabaseMetadata db = getDatabases().getCurrent();

    Intent intent = new Intent(getContext(), SyncService.class);

    intent.setAction(SyncConstants.INTENT_ACTION_SYNC);

    intent.putExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE, db.localPath);
    intent.putExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE, db.remotePath);

    return PendingIntent.getService(getContext(), SyncConstants.REQUEST_DELAYED_SYNC, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.money.manager.ex.sync.SyncManager.java

public void triggerUpload() {
    DatabaseMetadata db = getDatabases().getCurrent();
    if (db == null) {
        throw new RuntimeException("Cannot upload: local database not set.");
    }/*from  w  w w . j ava 2  s.c  o m*/
    String localFile = db.localPath;
    String remoteFile = db.remotePath;

    // trigger upload
    Intent service = new Intent(getContext(), SyncService.class);
    service.setAction(SyncConstants.INTENT_ACTION_UPLOAD);
    service.putExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE, localFile);
    service.putExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE, remoteFile);

    // start service
    getContext().startService(service);
}