Search in sources :

Example 91 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class HelpUtils method uriWithAddedParameters.

/**
     * Adds two query parameters into the Uri, namely the language code and the version code
     * of the app's package as gotten via the context.
     * @return the uri with added query parameters
     */
public static Uri uriWithAddedParameters(Context context, Uri baseUri) {
    Uri.Builder builder = baseUri.buildUpon();
    // Add in the preferred language
    builder.appendQueryParameter(PARAM_LANGUAGE_CODE, Locale.getDefault().toString());
    // Add in the package version code
    if (sCachedVersionCode == null) {
        // There is no cached version code, so try to get it from the package manager.
        try {
            // cache the version code
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            sCachedVersionCode = Integer.toString(info.versionCode);
            // append the version code to the uri
            builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
        } catch (NameNotFoundException e) {
            // Cannot find the package name, so don't add in the version parameter
            // This shouldn't happen.
            Log.wtf(TAG, "Invalid package name for context", e);
        }
    } else {
        builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
    }
    // Build the full uri and return it
    return builder.build();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Uri(android.net.Uri)

Example 92 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class PowerNotificationWarnings method attachLowBatterySound.

private void attachLowBatterySound(Notification.Builder b) {
    final ContentResolver cr = mContext.getContentResolver();
    final int silenceAfter = Settings.Global.getInt(cr, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, 0);
    final long offTime = SystemClock.elapsedRealtime() - mScreenOffTime;
    if (silenceAfter > 0 && mScreenOffTime > 0 && offTime > silenceAfter) {
        Slog.i(TAG, "screen off too long (" + offTime + "ms, limit " + silenceAfter + "ms): not waking up the user with low battery sound");
        return;
    }
    if (DEBUG) {
        // WOMP-WOMP is deprecated
        Slog.d(TAG, "playing low battery sound. pick-a-doop!");
    }
    if (Settings.Global.getInt(cr, Settings.Global.POWER_SOUNDS_ENABLED, 1) == 1) {
        final String soundPath = Settings.Global.getString(cr, Settings.Global.LOW_BATTERY_SOUND);
        if (soundPath != null) {
            final Uri soundUri = Uri.parse("file://" + soundPath);
            if (soundUri != null) {
                b.setSound(soundUri, AUDIO_ATTRIBUTES);
                if (DEBUG)
                    Slog.d(TAG, "playing sound " + soundUri);
            }
        }
    }
}
Also used : Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 93 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class GlobalScreenshot method doInBackground.

@Override
protected Void doInBackground(Void... params) {
    if (isCancelled()) {
        return null;
    }
    // By default, AsyncTask sets the worker thread to have background thread priority, so bump
    // it back up so that we save a little quicker.
    Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
    Context context = mParams.context;
    Bitmap image = mParams.image;
    Resources r = context.getResources();
    try {
        // Create screenshot directory if it doesn't exist
        mScreenshotDir.mkdirs();
        // media provider uses seconds for DATE_MODIFIED and DATE_ADDED, but milliseconds
        // for DATE_TAKEN
        long dateSeconds = mImageTime / 1000;
        // Save
        OutputStream out = new FileOutputStream(mImageFilePath);
        image.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
        // Save the screenshot to the MediaStore
        ContentValues values = new ContentValues();
        ContentResolver resolver = context.getContentResolver();
        values.put(MediaStore.Images.ImageColumns.DATA, mImageFilePath);
        values.put(MediaStore.Images.ImageColumns.TITLE, mImageFileName);
        values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageFileName);
        values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, mImageTime);
        values.put(MediaStore.Images.ImageColumns.DATE_ADDED, dateSeconds);
        values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, dateSeconds);
        values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
        values.put(MediaStore.Images.ImageColumns.WIDTH, mImageWidth);
        values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
        values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
        Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        // Create a share intent
        String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
        String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("image/png");
        sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        // Create a share action for the notification
        PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        Intent chooserIntent = Intent.createChooser(sharingIntent, null, chooseAction.getIntentSender()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent shareAction = PendingIntent.getActivity(context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_share, r.getString(com.android.internal.R.string.share), shareAction);
        mNotificationBuilder.addAction(shareActionBuilder.build());
        // Create a delete action for the notification
        PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class).putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_delete, r.getString(com.android.internal.R.string.delete), deleteAction);
        mNotificationBuilder.addAction(deleteActionBuilder.build());
        mParams.imageUri = uri;
        mParams.image = null;
        mParams.errorMsgResId = 0;
    } catch (Exception e) {
        // IOException/UnsupportedOperationException may be thrown if external storage is not
        // mounted
        mParams.clearImage();
        mParams.errorMsgResId = R.string.screenshot_failed_to_save_text;
    }
    // Recycle the bitmap data
    if (image != null) {
        image.recycle();
    }
    return null;
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) Date(java.util.Date) Notification(android.app.Notification) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 94 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class GlobalScreenshot method doInBackground.

@Override
protected Void doInBackground(Uri... params) {
    if (params.length != 1)
        return null;
    Uri screenshotUri = params[0];
    ContentResolver resolver = mContext.getContentResolver();
    resolver.delete(screenshotUri, null, null);
    return null;
}
Also used : Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 95 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class NavBarTuner method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == READ_REQUEST && resultCode == Activity.RESULT_OK && data != null) {
        final Uri uri = data.getData();
        final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
        getContext().getContentResolver().takePersistableUriPermission(uri, takeFlags);
        mNavBarAdapter.onImageSelected(uri);
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Also used : Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)3406 Intent (android.content.Intent)732 Cursor (android.database.Cursor)466 ContentValues (android.content.ContentValues)349 File (java.io.File)339 IOException (java.io.IOException)254 ContentResolver (android.content.ContentResolver)242 ArrayList (java.util.ArrayList)209 Test (org.junit.Test)194 RemoteException (android.os.RemoteException)190 Bundle (android.os.Bundle)154 Bitmap (android.graphics.Bitmap)129 Context (android.content.Context)118 InputStream (java.io.InputStream)110 PendingIntent (android.app.PendingIntent)104 LargeTest (android.test.suitebuilder.annotation.LargeTest)97 View (android.view.View)95 FileNotFoundException (java.io.FileNotFoundException)94 Request (android.app.DownloadManager.Request)83 TextView (android.widget.TextView)73