List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:cn.com.caronwer.activity.AuthSecondActivity.java
public void startPhotoZoom(Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); String filename = BitmapUtil.getPath(this, uri); assert filename != null; uri = Uri.fromFile(new File(filename)); intent.setDataAndType(uri, "image/*"); // crop=true?IntentVIEW?? intent.putExtra("crop", true); intent.putExtra("scale", true);// ? intent.putExtra("scaleUpIfNeeded", true);// // aspectX aspectY intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX outputY ? intent.putExtra("outputX", 200); intent.putExtra("outputY", 200); intent.putExtra("return-data", true); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); startActivityForResult(intent, REQUEST_CODE_CUTTING); }
From source file:com.chasetech.pcount.autoupdate.AutoUpdateApk.java
protected void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { setChanged();//w w w . j a va2s .c om notifyObservers(AUTOUPDATE_HAVE_UPDATE); // raise notification // Notification notification = new Notification( // appIcon, appName + " update", System.currentTimeMillis()); // notification.flags |= NOTIFICATION_FLAGS; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Click this to install.."; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification.Builder builder = new Notification.Builder(context); builder.setAutoCancel(false); builder.setTicker("An update is available."); builder.setContentTitle(contentTitle); builder.setContentText(contentText); builder.setSmallIcon(appIcon); builder.setContentIntent(contentIntent); builder.setOngoing(true); builder.setSubText(appName + " update"); //API level 16 builder.setNumber(100); builder.build(); Notification myNotication = builder.getNotification(); nm.notify(NOTIFICATION_ID, myNotication); // notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); // nm.notify( NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } // if( update_file.length() > 0 ) { // setChanged(); // notifyObservers(AUTOUPDATE_HAVE_UPDATE); // // // raise notification ///* Notification notification = new Notification( // appIcon, appName + " update", System.currentTimeMillis());*/ // Notification.Builder notifBuilder = new Notification.Builder(context); // //notification.flags |= NOTIFICATION_FLAGS; // // CharSequence contentTitle = appName + " update available"; // CharSequence contentText = "Select to install"; // Intent notificationIntent = new Intent(Intent.ACTION_VIEW ); // Uri uriFile = Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file); // notificationIntent.setDataAndType(uriFile, ANDROID_PACKAGE); // PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); // // notifBuilder.setContentTitle(contentTitle); // notifBuilder.setContentText(contentText); // notifBuilder.setContentIntent(contentIntent); // notifBuilder.setSubText("Update available."); // notifBuilder.build(); // // Notification notification = notifBuilder.build(); // notification.flags |= NOTIFICATION_FLAGS; // // nm.notify(NOTIFICATION_ID, notification); // // //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); // //nm.notify( NOTIFICATION_ID, notification); // } else { // nm.cancel( NOTIFICATION_ID ); // } }
From source file:com.nookdevs.market.NookMarket.java
private void installPackage(String uri) { String path = "file://" + uri; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive"); startActivity(intent);//from w ww. j a v a2 s. com }
From source file:net.evecom.androidecssp.base.BaseWebActivity.java
/** * /* w ww . j a v a 2s . c o m*/ * * * @author Mars zhang * @created 2015-11-25 2:11:17 * @param file * @return */ public Intent getFileIntent(File file) { // Uri uri = Uri.parse("http://m.ql18.com.cn/hpf10/1.pdf"); Uri uri = Uri.fromFile(file); String type = getMIMEType(file); Log.i("tag", "type=" + type); Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(uri, type); return intent; }
From source file:net.reichholf.dreamdroid.activities.MovieListActivity.java
/** * @param ref/*from w w w. ja va 2 s . c o m*/ * A ServiceReference */ private void streamFile(String fileName) { Intent intent = new Intent(Intent.ACTION_VIEW); SimpleHttpClient shc = SimpleHttpClient.getInstance(); ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("file", fileName)); String uriString = shc.buildStreamUrl(URIStore.FILE, params); intent.setDataAndType(Uri.parse(uriString), "video/*"); startActivity(intent); }
From source file:abanoubm.dayra.main.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { if (Utility.getArabicLang(getApplicationContext()) == 1) { Utility.setArabicLang(getApplicationContext(), 2); Locale myLocale = new Locale("ar"); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;//from ww w. j a v a 2s. c om res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } super.onCreate(savedInstanceState); setContentView(R.layout.act_main); ((TextView) findViewById(R.id.subhead1)).setText(R.string.app_name); ((TextView) findViewById(R.id.subhead2)).setText(BuildConfig.VERSION_NAME); findViewById(R.id.nav_back).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); ((TextView) findViewById(R.id.footer)).setText("dayra " + BuildConfig.VERSION_NAME + " @" + new SimpleDateFormat("yyyy", Locale.getDefault()).format(new Date()) + " Abanoub M."); if (!Utility.getDayraName(getApplicationContext()).equals("")) { startActivity(new Intent(getApplicationContext(), Home.class)); finish(); } ListView lv = (ListView) findViewById(R.id.home_list); mMenuItemAdapter = new MenuItemAdapter(getApplicationContext(), new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.sign_menu))), 1); lv.setAdapter(mMenuItemAdapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: sign(); break; case 1: register(); break; case 2: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { importDB(); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, IMPORT_REQUEST); } break; case 3: startActivity(new Intent(Intent.ACTION_VIEW).setData( Uri.parse("https://drive.google.com/file/d/0B1rNCm5K9cvwVXJTTzNqSFdrVk0/view"))); break; case 4: startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( "https://drive.google.com/open?id=1flSRdoiIT_hNd96Kxz3Ww3EhXDLZ45FhwFJ2hF9vl7g"))); break; case 5: { AlertDialog.Builder builder = new AlertDialog.Builder(Main.this); builder.setTitle(R.string.label_choose_language); builder.setItems(getResources().getStringArray(R.array.language_menu), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String temp; if (which == 1) { temp = "en"; Utility.setArabicLang(getApplicationContext(), 0); } else { temp = "ar"; Utility.setArabicLang(getApplicationContext(), 2); } Locale myLocale = new Locale(temp); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } }); builder.create().show(); } break; case 6: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/453595434816965")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/dayraapp")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 7: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1363784786")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/EngineeroBono")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 8: Uri uri = Uri.parse("market://details?id=" + getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); try { startActivity(goToMarket); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } break; case 9: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*"); startActivity( intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, FOLDER_REQUEST); } break; case 10: LayoutInflater li = LayoutInflater.from(getApplicationContext()); final View aboutView = li.inflate(R.layout.dialogue_about, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(aboutView, 0, 0, 0, 0); ad.show(); ((TextView) aboutView.findViewById(R.id.about)) .setText(String.format(getResources().getString(R.string.copyright), Calendar.getInstance().get(Calendar.YEAR))); ((TextView) aboutView.findViewById(R.id.notice)).setText(GoogleApiAvailability.getInstance() .getOpenSourceSoftwareLicenseInfo(getApplicationContext())); aboutView.findViewById(R.id.btn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ad.cancel(); } }); break; } } }); }
From source file:com.android.music.ArtistAlbumBrowserFragment.java
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { mCurrentAlbumId = Long.valueOf(id).toString(); Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.setClass(getActivity(), TrackBrowserActivity.class); intent.putExtra("album", mCurrentAlbumId); Cursor c = (Cursor) mAdapter.getChild(groupPosition, childPosition); String album = c.getString(c.getColumnIndex(MediaStore.Audio.Albums.ALBUM)); if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) { // unknown album, so we should include the artist ID to limit the songs to songs only by that artist mArtistCursor.moveToPosition(groupPosition); mCurrentArtistId = mArtistCursor.getString(mArtistCursor.getColumnIndex(MediaStore.Audio.Artists._ID)); intent.putExtra("artist", mCurrentArtistId); }/*w w w.ja va2 s. c o m*/ startActivity(intent); return true; }
From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java
/** * @param ref/* ww w . j a v a2 s . c o m*/ * A ServiceReference */ private void streamService(String ref) { Intent intent = new Intent(Intent.ACTION_VIEW); String uriString = "http://" + DreamDroid.PROFILE.getStreamHost().trim() + ":8001/" + ref; Log.i(DreamDroid.LOG_TAG, "Streaming URL set to '" + uriString + "'"); intent.setDataAndType(Uri.parse(uriString), "video/*"); startActivity(intent); }
From source file:com.game.simple.Game3.java
public void cropImage(Uri pic) { if (pic == null) { return;//from w w w. j a v a2 s .c o m } try { Intent cropIntent = new Intent("com.android.camera.action.CROP"); //indicate image type and Uri cropIntent.setDataAndType(pic, "image/*"); //set crop properties cropIntent.putExtra("crop", "true"); //indicate aspect of desired crop cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); //indicate output X and Y cropIntent.putExtra("outputX", 256); cropIntent.putExtra("outputY", 256); //retrieve data on return cropIntent.putExtra("return-data", true); //start the activity - we handle returning in onActivityResult self.startActivityForResult(cropIntent, PIC_CROP); } catch (ActivityNotFoundException anfe) { //display an error message String errorMessage = "?in thoi khng h tr !"; Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT); toast.show(); } }
From source file:com.nnm.smsviet.Message.java
/** * Fetch MMS parts.//from ww w . j a v a 2 s . co m * * @param context * {@link Context} */ private void fetchMmsParts(final Context context) { final ContentResolver cr = context.getContentResolver(); Cursor cursor = cr.query(URI_PARTS, null, PROJECTION_PARTS[INDEX_MID] + " = ?", new String[] { String.valueOf(this.id) }, null); if (cursor == null || !cursor.moveToFirst()) { return; } final int iID = cursor.getColumnIndex(PROJECTION_PARTS[INDEX_ID]); final int iCT = cursor.getColumnIndex(PROJECTION_PARTS[INDEX_CT]); final int iText = cursor.getColumnIndex("text"); do { final int pid = cursor.getInt(iID); final String ct = cursor.getString(iCT); Log.d(TAG, "part: " + pid + " " + ct); // get part InputStream is = null; final Uri uri = ContentUris.withAppendedId(URI_PARTS, pid); try { is = cr.openInputStream(uri); } catch (IOException e) { Log.e(TAG, "Failed to load part data", e); } if (is == null) { Log.i(TAG, "InputStream for part " + pid + " is null"); if (iText >= 0 && ct.startsWith("text/")) { this.body = cursor.getString(iText); } continue; } if (ct == null) { continue; } if (ct.startsWith("image/")) { this.picture = BitmapFactory.decodeStream(is); final Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, ct); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); this.contentIntent = i; continue; // skip the rest } else if (ct.startsWith("video/") || ct.startsWith("audio/")) { this.picture = BITMAP_PLAY; final Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, ct); this.contentIntent = i; continue; // skip the rest } else if (ct.startsWith("text/")) { this.body = this.fetchPart(is); } if (is != null) { try { is.close(); } catch (IOException e) { Log.e(TAG, "Failed to close stream", e); } // Ignore } } while (cursor.moveToNext()); }