List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.cw.litenote.note_add.Note_addCameraImage.java
private void takeImageWithName() { Intent takeImageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takeImageIntent.resolveActivity(getPackageManager()) != null) { // Create temporary image File where the photo will save in File tempFile = null;/* w w w . ja va 2 s . co m*/ try { tempFile = createTempImageFile(); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (tempFile != null) { imageUri = Uri.fromFile(tempFile); // so far, file size is 0 takeImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // appoint Uri for captured image imageUriInDB = imageUri.toString(); startActivityForResult(takeImageIntent, TAKE_IMAGE_ACT); } } }
From source file:me.skydeveloper.tikona.SessionTab.java
/** * Updates Session Details returned from TikonaSession *//*w w w.ja va 2s. c om*/ protected void updateSessionDetails() { if (tikonaSession != null) { for (TikonaSession session : tikonaSession) { if (session.isLoggedIn()) { sessionStart.setText(session.getSessionStart()); sessionDuration.setText(session.getSessionDuration()); sessionUsage.setText(session.getSessionUsage()); long sessionStartMilli = 0; try { //TODO => Manage session when session is null error 100 - Logged in but button is not visible if (session.getSessionStart() != null) { Date sessionDateTime = new SimpleDateFormat("MM/dd/yyy HH:mm:ss", Locale.ENGLISH) .parse(session.getSessionStart()); sessionStartMilli = sessionDateTime.getTime(); } } catch (ParseException e) { e.printStackTrace(); } long currentTime = selfcarePreferences.getLong("lastCheckedAt", 0); /*SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d h:mm:ss", Locale.ENGLISH); String dateTime = null; try { Date date2 = dateFormat.parse(date.toString()); dateTime = dateFormat.format(date); } catch (ParseException e) { e.printStackTrace(); }*/ Date date = new Date(System.currentTimeMillis()); lastCheckedAt.setText(date.toString()); Log.d("timeTest", sessionStartMilli + ""); Log.d("timeTest", currentTime + ""); //Log.d("timeTest",currentTime + ""); if (sessionStartMilli > currentTime) { if (!selfcarePreferences.getString("username", "").equals("") && !selfcarePreferences.getString("password", "").equals("")) { remainingUsage.setText("Fetching details ..."); HttpRequest data = new HttpRequest(); data.setMethod("POST"); data.setUri("https://selfcare.tikona.in/EncryptData.do"); String username = selfcarePreferences.getString("username", ""); String password = selfcarePreferences.getString("password", ""); data.setParam("data", username + "~" + password); Selfcare selfcareData = new Selfcare(); selfcareData.execute(data); } else {// TextView remainingUsage = (TextView) getView().findViewById(R.id.remainigUsageValue); remainingUsage.setText(R.string.ltvd); //TODO => Uncomment this once selfcare login is fixed /*remainingUsage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), SelfcareLogin.class); startActivity(intent); } });*/ } } else {//If we already have selfcare data String balance = selfcarePreferences.getString("balance", "");//Already processed String current = sessionUsage.getText().toString().replace("MB", "").replace("GB", "") .replace("KB", "").replace("B", "").trim(); int remainingData = 0; if (current.length() >= 1 && !balance.equals("You are now on secondary policy")) { remainingData = Integer.parseInt(balance) - Integer.parseInt(current); if (remainingData > 0) { remainingUsage.setText(remainingData + " MB"); } else { remainingUsage.setText(R.string.secondaryPolicy); } } else { remainingUsage.setText(R.string.secondaryPolicy); } //FOR SCREENSHOT PURPOSES /*TextView test = (TextView) getActivity().findViewById(R.id.userid); test.setText("11XXXXXX"); TextView test2 = (TextView) getActivity().findViewById(R.id.name); test2.setText("Guest User");*/ } sessionEditor = sessionPreferences.edit(); sessionEditor.putString("sessionStart", session.getSessionStart()); sessionEditor.putString("sessionDuration", session.getSessionDuration()); sessionEditor.putString("sessionUsage", session.getSessionUsage()); sessionEditor.apply(); Snackbar.make(getView(), "Session details updated", Snackbar.LENGTH_LONG).show(); } else if (!session.isLogoutButtonVisibility()) { Toast.makeText(getActivity(), "Empty Response. This happens when logout button is not visible on login page. There is nothing can be done. :( ", Toast.LENGTH_LONG).show(); } else if (session.isCacheError()) { Toast.makeText(getActivity(), "Empty response. Happens randomly not my fault :) Try after some time", Toast.LENGTH_LONG).show(); //TODO => Extract method for updating selfcare easily } else { Toast.makeText(getActivity(), "You are not logged in. Redirecting to login page", Toast.LENGTH_LONG).show(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(REQUEST_DATA)); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(getActivity(), "No Browser found", Toast.LENGTH_SHORT).show(); } } Log.d("Session Start => ", "" + session.getSessionStart()); Log.d("Session Duration => ", "" + session.getSessionDuration()); Log.d("Session Usage => ", "" + session.getSessionUsage()); Log.d("IsLoggedIn => ", "" + session.isLoggedIn()); Log.d("LogoutButtonStatus => ", "" + session.isLogoutButtonVisibility()); break;//TODO => Temporary solution to prevent multiple loops } } }
From source file:com.truman.showtime.showtime.ui.fragment.TheaterListFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterViewCompat.AdapterContextMenuInfo info = (AdapterViewCompat.AdapterContextMenuInfo) item .getMenuInfo();/* w w w .j a v a 2 s .c o m*/ if (item.getTitle().equals(getString(R.string.directions_theater))) { String theaterString = null; try { theaterString = URLEncoder.encode(mSelectedTheater.address, "UTF-8"); Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + theaterString); // Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); // Make the Intent explicit by setting the Google Maps package // mapIntent.setPackage("com.google.android.apps.maps"); // Attempt to start an activity that can handle the Intent if (mapIntent.resolveActivity(mApplicationContext.getPackageManager()) != null) { startActivity(mapIntent); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else if (item.getTitle().equals(getString(R.string.share_theater))) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, mSelectedTheater.name + "\n" + mSelectedTheater.address + "\n" + "http://google.com/movies?near=" + mCity + "&tid=" + mSelectedTheater.id); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.share_theater))); } return super.onContextItemSelected(item); }
From source file:org.stenerud.kscrash.KSCrashReportFilterEmail.java
@Override public void filterReports(List reports, CompletionCallback completionCallback) throws KSCrashReportFilteringFailedException { ArrayList<Uri> attachments = new ArrayList<>(); String authority = BuildConfig.APPLICATION_ID + ".provider"; for (Object report : reports) { attachments.add(FileProvider.getUriForFile(context, authority, (File) report)); }//from www . java 2 s.c o m Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("*/*"); // TODO: Why does this fail? // intent.setData(Uri.parse("mailto:")); intent.putExtra(Intent.EXTRA_EMAIL, recipients.toArray()); intent.putExtra(Intent.EXTRA_SUBJECT, subject); // Workaround for framework bug ArrayList<String> text = new ArrayList<>(); text.add(message); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_STREAM, attachments); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } completionCallback.onCompletion(reports); }
From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java
/** * Start the camera by dispatching a camera intent. *///w ww . ja va 2 s . c om protected void dispatchTakePictureIntent(boolean isFinishingService) { // Check if there is a camera. Context context = getActivity(); PackageManager packageManager = context.getPackageManager(); if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) { Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show(); return; } // Camera exists? Then proceed... Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent DetalleServicioActivity activity = (DetalleServicioActivity) getActivity(); if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go. // If you don't do this, you may get a crash in some devices. File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File Toast toast = Toast.makeText(activity, "There was a problem saving the photo...", Toast.LENGTH_SHORT); toast.show(); } // Continue only if the File was successfully created if (photoFile != null) { Uri fileUri = Uri.fromFile(photoFile); activity.setCapturedImageURI(fileUri); activity.setCurrentPhotoPath(fileUri.getPath()); activity.setIsFinishingService(isFinishingService); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, activity.getCapturedImageURI()); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:com.vyasware.vaani.MainActivity.java
private void performAction(String input) { String[] verbs = { "", "", "", "?", "", "?", "", "", "", "", "", "", "", "", "", "weather", "?", "?", "", "", "?" }; String[] actions = { "call", "call", "call", "call", "msg", "msg", "msg", "msg", "open", "open", "open", "weather", "weather", "weather", "weather", "weather", "greet", "greet", "greet", "greet", "greet" }; String[] sentence = input.split(" "); String action = "", noun = "", result = ""; int verbindex = -1, nounindex = -1; for (String word : sentence) { //out.println(word); for (int i = 0; i < verbs.length; i++) { //System.out.println(verbs[i]); if (word.equalsIgnoreCase(verbs[i])) verbindex = i;/*from w w w. java 2 s.c o m*/ } if (verbindex >= 0) { // out.println("true"); action = actions[verbindex]; System.out.println(action); break; } } for (int j = 0; j < sentence.length; j++) { if (sentence[j].equalsIgnoreCase("")) { nounindex = j - 1; } } if (nounindex >= 0) noun = sentence[nounindex]; String search = "google!"; if (action.equals("")/*||noun.equals("")*/) { tts.speak(search, TextToSpeech.QUEUE_FLUSH, null); Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, returnedText.getText()); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); } else if (action.equals("call")) doCall(noun); else if (action.equals("msg")) doMsg(noun); else if (action.equals("open")) doOpen(sentence); else if (action.equals("weather")) doWeather(); else if (action.equals("greet")) doGreet(); // tts.speak(result,TextToSpeech.QUEUE_FLUSH, null); }
From source file:com.vyasware.vaani.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); returnedText = (TextView) findViewById(R.id.textView1); outputText = (TextView) findViewById(R.id.textView2); progressBar = (ProgressBar) findViewById(R.id.progressBar1); toggleButton = (ToggleButton) findViewById(R.id.toggleButton1); progressBar.setVisibility(View.INVISIBLE); speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, // "en"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName()); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "hi-IN"); recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override// w w w . j a va2 s .c o m public void onInit(int status) { if (status != TextToSpeech.ERROR) { tts.setLanguage(new Locale("hi_IN")); tts.setSpeechRate(0.9f); } } }); returnedText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, returnedText.getText()); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); } }); toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(true); speech.startListening(recognizerIntent); outputText.setText(""); } else { progressBar.setIndeterminate(false); progressBar.setVisibility(View.INVISIBLE); speech.stopListening(); } } }); }
From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java
/** * Add the activity parent chain as specified by manifest <meta-data> * elements to the task stack builder.// w ww. j av a2 s. c o m * * @param sourceActivity * All parents of this activity will be added * @return This DualTaskStackBuilder for method chaining */ public DualTaskStackBuilder addParentStack(Activity sourceActivity) { final Intent parent = DualNavUtils.getParentActivityIntent(sourceActivity); if (parent != null) { // We have the actual parent intent, build the rest from static // metadata // then add the direct parent intent to the end. ComponentName target = parent.getComponent(); if (target == null) { target = parent.resolveActivity(mSourceContext.getPackageManager()); } addParentStack(target); addNextIntent(parent); } return this; }
From source file:com.hplasplas.cam_capture.activitys.CamCapture.java
public void makePhoto() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); mCurrentPictureFile = FileSystemManager.generateFileForPicture(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCurrentPictureFile)); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, GET_PICTURE_REQUEST_CODE); }//from ww w .j av a 2 s . c om }
From source file:com.notepadlite.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 w w w .jav a 2s. co 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: // Set current note contents to a String String contents = noteContents.getText().toString(); // Send a share intent Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, contents); 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; default: return super.onOptionsItemSelected(item); } }