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.example.android.wifidirect.DeviceDetailFragment.java

@Override
public void onConnectionInfoAvailable(final WifiP2pInfo info) {
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();/*from ww w.  j a  va2 s. c om*/
    }
    this.info = info;
    this.getView().setVisibility(View.VISIBLE);

    // The owner IP is now known.
    TextView view = (TextView) mContentView.findViewById(R.id.group_owner);
    view.setText(getResources().getString(R.string.group_owner_text)
            + ((info.isGroupOwner == true) ? getResources().getString(R.string.yes)
                    : getResources().getString(R.string.no)));

    // InetAddress from WifiP2pInfo struct.
    view = (TextView) mContentView.findViewById(R.id.device_info);
    view.setText("Group Owner IP - " + info.groupOwnerAddress.getHostAddress());

    // After the group negotiation, we assign the group owner as the file
    // server. The file server is single threaded, single connection server
    // socket.
    if (info.groupFormed && info.isGroupOwner) {
        new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text)).execute();
    } else if (info.groupFormed) {
        // The other device acts as the client. In this case, we enable the
        // get file button.
        mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE);
        ((TextView) mContentView.findViewById(R.id.status_text))
                .setText(getResources().getString(R.string.client_text));
        mContentView.findViewById(R.id.details_layout).setVisibility(View.VISIBLE);
        mContentView.findViewById(R.id.btn_send_data).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // Allow user to pick an image from Gallery or other
                // registered apps

                TextView statusText = (TextView) mContentView.findViewById(R.id.status_text);
                EditText mName = (EditText) mContentView.findViewById(R.id.nameField);
                EditText mAddress = (EditText) mContentView.findViewById(R.id.addressField);
                EditText mAge = (EditText) mContentView.findViewById(R.id.ageField);
                EditText mMessage = (EditText) mContentView.findViewById(R.id.messageField);
                String name = mName.getText().toString();
                String address = mAddress.getText().toString();
                String age = mAge.getText().toString();
                String message = mMessage.getText().toString();
                JSONObject data_object = new JSONObject();
                try {
                    data_object.put("name", name);
                    data_object.put("address", address);
                    data_object.put("age", age);
                    data_object.put("message", message);

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

                statusText.setText("Sending: " + data_object.toString());
                Log.d(WiFiDirectActivity.TAG, "Intent----------- " + data_object.toString());
                Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
                serviceIntent.setAction(FileTransferService.ACTION_SEND_DATA);
                serviceIntent.putExtra(FileTransferService.EXTRAS_DATA, data_object.toString());
                serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS,
                        info.groupOwnerAddress.getHostAddress());
                serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8988);
                getActivity().startService(serviceIntent);

            }
        });
    }

    // hide the connect button
    mContentView.findViewById(R.id.btn_connect).setVisibility(View.GONE);
}

From source file:ms.globalclass.netty.SecureChatClientHandler.java

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    System.err.println("dddddd==========" + e.getMessage().toString());
    String jsonstr = e.getMessage().toString();
    try {/* w  w  w  .j  a va  2 s .c o m*/
        JSONObject jobobj = new JSONObject(jsonstr);
        JSONObject job = null;
        boolean b = true;
        String pusid = null;
        if (jobobj.has("uuid")) {
            pusid = jobobj.getString("uuid");
            job = jobobj.getJSONObject("jsonstr");
            //               MainTabActivity.instance.confirmPusMessage(pusid);
            if (pusids.contains(pusid)) {
                System.out.println("size===========" + pusids.size());
                b = false;
            } else {
                pusids.add(pusid);
            }
        } else {
            job = new JSONObject(jsonstr);
        }
        //         JSONObject job = new JSONObject(jsonstr);

        if (b) {
            if (job.has("nettyid")) {
                int nettyid = job.getInt("nettyid");
                myapp.setNettyid(nettyid);

                JSONObject nettyjob = new JSONObject();
                nettyjob.put("online", String.valueOf(nettyid));
                nettyjob.put("userid", myapp.getUserNameId());
                nettyjob.put("username", myapp.getUserName());
                if (myapp.getIsServer()) {
                    nettyjob.put("role", myapp.getCompanyid());
                    nettyjob.put("storeid", myapp.getAppstoreid());
                }
                String jsonstrs = nettyjob.toString();
                ChannelFuture lastWriteFuture = null;
                lastWriteFuture = myapp.getChannel().write(jsonstrs + "\r\n");

                if (nettyid != 0) {
                    Intent intent = new Intent();
                    intent.putExtra("pusid", pusid);
                    intent.setAction("unread_message_pus_hua_meida");
                    context.sendBroadcast(intent);
                }
            } else if (job.has("online"))//
            {
                String nettyid = job.getString("online");
                String userid = job.getString("userid");
                String username = job.getString("username");

                Map<String, Object> usermap = new HashMap<String, Object>();
                usermap.put("nettyid", nettyid);
                usermap.put("userid", userid);
                usermap.put("username", username);
                myapp.getOnlineUserList().put(nettyid, usermap);

                Intent intent = new Intent();
                intent.putExtra("nettyid", nettyid);
                intent.putExtra("userid", userid);
                intent.putExtra("username", username);
                intent.setAction("USER_ONLINE");
                context.sendBroadcast(intent);
            } else if (job.has("downline"))//
            {
                int id = job.getInt("downline");
                String nettyid = String.valueOf(id);
                Map<String, Object> usermap = myapp.getOnlineUserList().get(nettyid);
                if (usermap != null) {
                    String username = (String) usermap.get("username");
                    myapp.getOnlineUserList().remove(nettyid);

                    Intent intent = new Intent();
                    intent.putExtra("nettyid", nettyid);
                    intent.putExtra("username", username);
                    intent.setAction("USER_DOWNLINE");
                    context.sendBroadcast(intent);
                }
            } else if (job.has("address"))//
            {
                String msg = job.getString("msg");
                JSONObject job2 = job.getJSONObject("address");
                JSONObject addressjob = job2.getJSONObject("address");
                String hostName = job2.getString("hostName");
                String port = String.valueOf(job2.getInt("port"));
                String hostAddress = addressjob.getString("hostAddress");

                Intent intent = new Intent();
                intent.putExtra("msg", msg);
                intent.putExtra("hostName", hostName);
                intent.putExtra("port", port);
                intent.putExtra("hostAddress", hostAddress);
                intent.setAction("NEW_MESSAGE");
                context.sendBroadcast(intent);
            } else if (job.has("new_message")) {
                Intent intent = new Intent();
                intent.setAction("NEW_MESSAGE_LIST_HUA_MEIDA");
                context.sendBroadcast(intent);
            } else if (job.has("automatic_message_pus")) {
                JSONArray jArry = new JSONArray();
                JSONObject mjob = job.getJSONObject("automatic_message_pus");
                jArry.put(mjob);
                Intent intent = new Intent();
                intent.putExtra("datastr", jArry.toString());
                intent.putExtra("pusid", pusid);
                intent.setAction("AUTOMATIC_MESSAGE_PUS_HUA_MEIDA");
                context.sendBroadcast(intent);
            } else if (job.has("verification_message_pus")) {
                Intent intent = new Intent();
                intent.putExtra("pusid", pusid);
                intent.setAction("VERIFICATION_MESSAGE_PUS_HUA_MEIDA");
                context.sendBroadcast(intent);
            } else if (job.has("friend_moments_pus")) {
                JSONArray momentfilearray = job.getJSONArray("friend_moments_files_pus");
                JSONObject momentsobj = job.getJSONObject("friend_moments_pus");
                String puspfid = job.getString("update_moments_pfid_pus");
                Intent intent = new Intent();
                intent.putExtra("moments", momentsobj.toString());
                intent.putExtra("momentsfiles", momentfilearray.toString());
                intent.putExtra("puspfid", puspfid);
                intent.putExtra("pusid", pusid);
                intent.setAction("MOMENTS_NEW_PUS_HUA_MEIDA");
                context.sendBroadcast(intent);
            } else if (job.has("gongao_moments_pus")) {
                JSONArray momentfilearray = job.getJSONArray("friend_moments_files_pus");
                JSONObject momentsobj = job.getJSONObject("gongao_moments_pus");
                String puspfid = job.getString("update_moments_pfid_pus");
                Intent intent = new Intent();
                intent.putExtra("moments", momentsobj.toString());
                intent.putExtra("momentsfiles", momentfilearray.toString());
                intent.putExtra("puspfid", puspfid);
                intent.putExtra("pusid", pusid);
                intent.setAction("MOMENTS_GONGAO_NEW_PUS_HUA_MEIDA");
                context.sendBroadcast(intent);
            } else if (job.has("confirm_message_pus"))//
            {
                String mid = job.getString("confirm_message_pus");
                Intent intent = new Intent();
                intent.putExtra("mid", mid);
                intent.putExtra("pusid", pusid);
                intent.setAction("CONFIRM_MESSAGE_PUS_HUA_MEIDA");
                context.sendBroadcast(intent);
            }
            //         else if(job.has("unread_message_pus_hua_meida"))
            //         {
            //            JSONArray jArry = new JSONArray();
            //            jArry = job.getJSONArray("unread_message_pus_hua_meida");
            //            Intent intent = new Intent();
            //            intent.putExtra("datastr",jArry.toString());
            //            intent.setAction("unread_message_pus_hua_meida");
            //            context.sendBroadcast(intent);
            //         }
            else//
            {
                String msg = job.getString("msg");
                Intent intent = new Intent();
                intent.putExtra("msg", msg);
                intent.setAction("MY_MESSAGE");
                context.sendBroadcast(intent);
            }
        }
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        //         e1.printStackTrace();
        if (jsonstr.equals("xintiao...")) {
            System.out.println("");
        } else {
            e1.printStackTrace();
        }
    }
}

From source file:org.ueu.uninet.it.IragarkiaBidali.java

/**
 * Prestatu iragarki berria bidaltzeko formularioa
 *//*from w  ww. j a  va  2 s.  c  o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.iragarkia_bidali);

    this.ekintza = this;
    this.izena = (EditText) findViewById(R.id.editTextIzena);
    this.izenburua = (EditText) findViewById(R.id.editTextIzenburua);
    this.eposta = (EditText) findViewById(R.id.editTextEposta);
    this.telefonoa = (EditText) findViewById(R.id.editTextTelefonoa);
    this.mezua = (EditText) findViewById(R.id.editTextDeskribapena);
    this.ohar_legala = (CheckBox) findViewById(R.id.checkBoxlegalAdviceBidali);
    this.errobota = (EditText) findViewById(R.id.editTextErrobota);

    this.atala = (Spinner) findViewById(R.id.spinnerAtala);
    imgView = (ImageView) findViewById(R.id.ImageView);
    upload = (Button) findViewById(R.id.Upload);
    bidali = (Button) findViewById(R.id.iragarkiaBidali);

    // Iragarkiak irudirik badu galeriatik kargatu
    upload.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Aukeratu irudi bat.", Toast.LENGTH_SHORT).show();
            try {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Irudia aukeratu"), PICK_IMAGE);
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });

    // Formularioa bidali
    bidali.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (balidatu()) {
                dialog = ProgressDialog.show(IragarkiaBidali.this, "Fitxategia igotzen eta mezua bidaltzen",
                        "Itxaron mesedez...", true);
                //Formularioa eta irudia bidali
                new ImageUploadTask().execute();
            }

        }
    });

    ArrayAdapter<String> iragarki_motak = new ArrayAdapter<String>(this, R.layout.spinner_view,
            getResources().getStringArray(R.array.iragarki_kategoriak));
    iragarki_motak.setDropDownViewResource(R.layout.spinner_view_dropdown);
    this.atala.setAdapter(iragarki_motak);

    // Sareko monitora prestatu
    NetworkConnectivity.sharedNetworkConnectivity().configure(this);
    NetworkConnectivity.sharedNetworkConnectivity().addNetworkMonitorListener(this);
    NetworkConnectivity.sharedNetworkConnectivity().startNetworkMonitor();

}

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

/** Start a new activity either in a new task or the current task. */
public void startActivity(Class<?> activityClass) {
    Intent intent = new Intent(context.getInstrumentation().getContext(), activityClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    context.getInstrumentation().startActivitySync(intent);
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

/**
 * Export the Sensor Database (SensorData as the name for the sqlite db on Android) as
 * csv file(s) or JSON file(s). Each type of sensor data in the database
 * will be export it as one file.//from  w  w  w  .  j a  va2  s.c  om
 * The export path is under SDcard/packageName/export/
 */
@SimpleFunction(description = "Export all sensor data as CSV files")
public void ExportSensorDB() {
    Log.i(TAG, "Exporting DB as CSV files");
    Log.i(TAG, "exporting data...at: " + System.currentTimeMillis());

    Bundle b = new Bundle();
    b.putString(NameValueDatabaseService.DATABASE_NAME_KEY, SensorDbUtil.DB_NAME);
    b.putString(NameValueDatabaseService.EXPORT_KEY, this.exportFormat);
    Intent i = new Intent(mBoundFunfManager, NameValueDatabaseService.class);
    i.setAction(DatabaseService.ACTION_EXPORT);
    i.putExtras(b);
    mBoundFunfManager.startService(i);
}

From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

public void setupShareIntent() {
    // Fetch Bitmap Uri locally
    ImageView ivImage = (ImageView) findViewById(R.id.ivCampaighnImage);
    // Get access to the URI for the bitmap
    Uri bmpUri = getLocalBitmapUri(ivImage);
    if (bmpUri != null) {
        // Construct a ShareIntent with link to image
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, campaign.getTitle());
        shareIntent.putExtra(Intent.EXTRA_TEXT, campaign.getCampaignUrl());
        shareIntent.setType("image/*");
        // Launch sharing dialog for image
        startActivity(Intent.createChooser(shareIntent, "send"));
    } else {// ww w .j a  v a2s  .  c o  m
        Toast.makeText(this, "Some error occured during sharing", Toast.LENGTH_LONG).show();

    }

}

From source file:com.openerp.base.ir.Attachment.java

public void requestAttachment(Types type) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    switch (type) {
    case IMAGE_OR_CAPTURE_IMAGE:
        // createDialog(type);
        // break;
    case IMAGE://from   w ww .ja  va  2s.  c  om
        intent.setType("image/*");
        requestIntent(intent, REQUEST_IMAGE);
        break;
    case CAPTURE_IMAGE:
        intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        requestIntent(intent, REQUEST_CAMERA);
        break;
    case AUDIO:
        intent.setType("audio/*");
        requestIntent(intent, REQUEST_AUDIO);
        break;
    case FILE:
        intent.setType("application/file");
        requestIntent(intent, REQUEST_FILE);
        break;
    default:
        break;
    }

}

From source file:com.gcm.client.GcmHelper.java

/**
 * Un-subscribe from specific topics/* ww  w .j ava  2s. c o m*/
 *
 * @param context      An instance of the application {@link Context}
 * @param removeTopics list of topics which needs to be removed from subscription
 */
public boolean unSubscribeTopic(@NonNull Context context, @NonNull String[] removeTopics) {
    if (!initialized)
        init(context);
    if (removeTopics.length == 0)
        return false;
    for (String topic : removeTopics) {
        topics.remove(topic);
    }
    Intent intent = new Intent(context, RegistrationIntentService.class);
    intent.setAction(RegistrationIntentService.ACTION_UNSUBSCRIBE);
    intent.putExtra(RegistrationIntentService.EXTRA_TOPIC_LIST, removeTopics);
    context.startService(intent);
    return true;
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

protected void saveToDB(IJsonObject completeProbeUri, IJsonObject data) {

    Log.i(TAG, "Writing data: " + completeProbeUri + ": " + data.toString());
    final JsonObject dataObject = data.getAsJsonObject();
    dataObject.add("probe", completeProbeUri.get(RuntimeTypeAdapterFactory.TYPE));
    dataObject.add("timezoneOffset", new JsonPrimitive(localOffsetSeconds)); // nice
    // move//from w  w w .j  a  va2 s  .  c o m
    final long timestamp = data.get(BaseProbeKeys.TIMESTAMP).getAsLong();
    final String probeName = completeProbeUri.get("@type").getAsString();

    Bundle b = new Bundle();
    b.putString(NameValueDatabaseService.DATABASE_NAME_KEY, PROBE_BASE_NAME);
    b.putLong(NameValueDatabaseService.TIMESTAMP_KEY, timestamp);
    b.putString(NameValueDatabaseService.NAME_KEY, probeName);
    b.putString(NameValueDatabaseService.VALUE_KEY, dataObject.toString());
    Intent i = new Intent(mBoundFunfManager, NameValueDatabaseService.class);
    i.setAction(DatabaseService.ACTION_RECORD);
    i.putExtras(b);
    mBoundFunfManager.startService(i);

}