Java Code Examples for android.content.Intent#setClipData()

The following examples show how to use android.content.Intent#setClipData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShareHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public static Intent getShareIntent(String title, String url, Uri screenshotUri) {
    url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, url);
    if (screenshotUri != null) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        // To give read access to an Intent target, we need to put |screenshotUri| in clipData
        // because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for
        // EXTRA_SHARE_SCREENSHOT_AS_STREAM.
        intent.setClipData(ClipData.newRawUri("", screenshotUri));
        intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri);
    }
    return intent;
}
 
Example 2
Source File: TakePhotoActivity.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPackagename = getIntent().getStringExtra(EXTRA_PACKAGENAME);
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

        mCameraUri = TemporaryContentProvider.Companion.prepare(this, "image/jpeg", TemporaryContentProvider.TTL_5_MINUTES, TemporaryContentProvider.TAG_CAMERA_SHOT);
        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        takePictureIntent.setClipData(ClipData.newRawUri(null, mCameraUri));
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);

        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    } else {
        finish();
    }
}
 
Example 3
Source File: ActionSendTask.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
public static void sendFiles(Context context, ArrayList<Uri> uris, String mime, ClipData clipData)
{
	if(uris == null || uris.isEmpty())
		return;

	Intent actionIntent = new Intent(uris.size() > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND);
	actionIntent.setType(mime == null ? "*/*" : mime);
	if (uris.size() > 1)
		actionIntent.putExtra(Intent.EXTRA_STREAM, uris);
	else
		actionIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && clipData!=null)
	{
		actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
		actionIntent.setClipData(clipData);
	}

	Intent startIntent = Intent.createChooser(actionIntent, context.getString(R.string.send_files_to));
	startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	context.startActivity(startIntent);
}
 
Example 4
Source File: AboutDialogBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
private void sendLogFile(Location logLocation)
{
	Context ctx = getActivity();
	Uri uri = MainContentProvider.getContentUriFromLocation(logLocation);
	Intent actionIntent = new Intent(Intent.ACTION_SEND);
	actionIntent.setType("text/plain");
	actionIntent.putExtra(Intent.EXTRA_STREAM, uri);
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		ClipData cp = ClipData.newUri(
				ctx.getContentResolver(),
				ctx.getString(R.string.get_program_log),
				uri
		);
		actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
		actionIntent.setClipData(cp);
	}

	Intent startIntent = Intent.createChooser(
			actionIntent,
			ctx.getString(R.string.save_log_file_to)
	);
	startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	ctx.startActivity(startIntent);
}
 
Example 5
Source File: SelectFileDialog.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Uri result) {
    mCameraOutputUri = result;
    if (mCameraOutputUri == null && captureCamera()) {
        onFileNotSelected();
        return;
    }

    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    camera.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        camera.setClipData(ClipData.newUri(
                mWindowAndroid.getApplicationContext().getContentResolver(),
                UiUtils.IMAGE_FILE_PATH, mCameraOutputUri));
    }
    if (mDirectToCamera) {
        mWindow.showIntent(camera, mCallback, R.string.low_memory_error);
    } else {
        launchSelectFileWithCameraIntent(true, camera);
    }
}
 
Example 6
Source File: AlbumActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
public void setPhotosResult() {
    final AlbumItem[] selected_items = SelectorModeManager
            .createAlbumItemArray(recyclerViewAdapter.cancelSelectorMode(this));

    Intent intent = new Intent("us.koller.RESULT_ACTION");
    if (allowMultiple) {
        ClipData clipData = createClipData(selected_items);
        intent.setClipData(clipData);
    } else {
        intent.setData(selected_items[0].getUri(this));
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    setResult(RESULT_OK, intent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        finishAfterTransition();
    } else {
        finish();
    }
}
 
Example 7
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);
        }
        else{
            intent.setData(uris[0]);
        }
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 8
Source File: UserEditActivity.java    From Android-IM with Apache License 2.0 6 votes vote down vote up
public void startPhotoZoom(Uri uri) {
    Log.e("uri=====", "" + uri);
    Intent intent = new Intent("com.android.camera.action.CROP");

    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("outputX", 60);
    intent.putExtra("outputY", 60);
    //uritempFile为Uri类变量,实例化uritempFile
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        //开启临时权限
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        //重点:针对7.0以上的操作
        intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, uri));
        uritempFile = uri;
    } else {
        uritempFile = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/" + "small.jpg");
    }
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uritempFile);
    intent.putExtra("return-data", false);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    intent.putExtra("noFaceDetection", true);
    startActivityForResult(intent, PHOTO_CLIP);
}
 
Example 9
Source File: MainActivity.java    From android-SharingShortcuts with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a sample share {@link Intent}.
 */
private void share() {
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, mEditBody.getText().toString());
    // (Optional) If you want a preview title, set it with Intent.EXTRA_TITLE
    sharingIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.send_intent_title));

    // (Optional) if you want a preview thumbnail, create a content URI and add it
    // The system only supports content URIs
    ClipData thumbnail = getClipDataThumbnail();
    if (thumbnail != null) {
        sharingIntent.setClipData(thumbnail);
        sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    startActivity(Intent.createChooser(sharingIntent, null));
}
 
Example 10
Source File: ShareHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static Intent getShareIntent(Activity activity, String title, String text, String url,
        Uri offlineUri, Uri screenshotUri) {
    if (!TextUtils.isEmpty(url)) {
        url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
        if (!TextUtils.isEmpty(text)) {
            // Concatenate text and URL with a space.
            text = text + " " + url;
        } else {
            text = url;
        }
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    intent.putExtra(EXTRA_TASK_ID, activity.getTaskId());

    if (screenshotUri != null) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    if (screenshotUri != null) {
        // To give read access to an Intent target, we need to put |screenshotUri| in clipData
        // because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for
        // EXTRA_SHARE_SCREENSHOT_AS_STREAM.
        intent.setClipData(ClipData.newRawUri("", screenshotUri));
        intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri);
    }
    if (offlineUri == null) {
        intent.setType("text/plain");
    } else {
        intent.setType("multipart/related");
        intent.putExtra(Intent.EXTRA_STREAM, offlineUri);
    }
    return intent;
}
 
Example 11
Source File: RemoteInputCompatJellybean.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
static void addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs, Intent intent,
        Bundle results) {
    Bundle resultsBundle = new Bundle();
    for (RemoteInputCompatBase.RemoteInput remoteInput : remoteInputs) {
        Object result = results.get(remoteInput.getResultKey());
        if (result instanceof CharSequence) {
            resultsBundle.putCharSequence(remoteInput.getResultKey(), (CharSequence) result);
        }
    }
    Intent clipIntent = new Intent();
    clipIntent.putExtra(EXTRA_RESULTS_DATA, resultsBundle);
    intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipIntent));
}
 
Example 12
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));

    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);	
        }
        else{
        	intent.setData(uris[0]);
        }
    }

    if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 13
Source File: ContactDetailFragment.java    From Contacts with MIT License 5 votes vote down vote up
private void doCropPhoto(Uri uri)
{
	Log.d("ContactDetailFragment", "doCropPhoto: ");
	tmpCroppedPhotoUri = generateTempCroppedImageUri(getActivity());

	int maxSize = getMaxSize();

	Intent intent = new Intent("com.android.camera.action.CROP");
	intent.setDataAndType(uri, "image/*");
	intent.putExtra("output", uri);
	intent.addFlags(3);
	intent.setClipData(ClipData.newRawUri("output", uri));
	intent.putExtra("crop", "true");
	intent.putExtra("scale", true);
	intent.putExtra("scaleUpIfNeeded", true);
	intent.putExtra("aspectX", 1);
	intent.putExtra("aspectY", 1);
	intent.putExtra("outputX", maxSize);
	intent.putExtra("outputY", maxSize);

	try
	{
		startActivityForResult(intent, CROP_PHOTO_CODE);
		return;
	}
	catch (Exception exception)
	{
		Log.e("ContactDetailFragment", "Cannot crop image", exception);
	}
}
 
Example 14
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));

    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);	
        }
        else{
        	intent.setData(uris[0]);
        }
    }

    if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 15
Source File: BrowserServiceFileProvider.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * Grant the read permission to a list of {@link Uri} sent through a {@link Intent}.
 * @param intent The sending Intent which holds a list of Uri.
 * @param uris A list of Uri generated by generateUri(Context, Bitmap, String, int,
 *             List<String>).
 * @param context The context requests to grant the permission.
 */
public static void grantReadPermission(Intent intent, List<Uri> uris, Context context) {
    if (uris == null || uris.size() == 0) return;
    ContentResolver resolver = context.getContentResolver();
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    ClipData clipData = ClipData.newUri(resolver, CLIP_DATA_LABEL, uris.get(0));
    for (int i = 1; i < uris.size(); i++) {
        clipData.addItem(new ClipData.Item(uris.get(i)));
    }
    intent.setClipData(clipData);
}
 
Example 16
Source File: ShareHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static Intent getShareIntent(Activity activity, String title, String text, String url,
        Uri offlineUri, Uri screenshotUri) {
    if (!TextUtils.isEmpty(url)) {
        url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
        if (!TextUtils.isEmpty(text)) {
            // Concatenate text and URL with a space.
            text = text + " " + url;
        } else {
            text = url;
        }
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    intent.putExtra(EXTRA_TASK_ID, activity.getTaskId());

    if (screenshotUri != null) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    if (screenshotUri != null) {
        // To give read access to an Intent target, we need to put |screenshotUri| in clipData
        // because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for
        // EXTRA_SHARE_SCREENSHOT_AS_STREAM.
        intent.setClipData(ClipData.newRawUri("", screenshotUri));
        intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri);
    }
    if (offlineUri == null) {
        intent.setType("text/plain");
    } else {
        intent.setType("multipart/related");
        intent.putExtra(Intent.EXTRA_STREAM, offlineUri);
    }
    return intent;
}
 
Example 17
Source File: FullScreenImageActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == R.id.shareOptions) {

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);

        Uri uri = ALFileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0)));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip =
                    ClipData.newUri(getContentResolver(), "a Photo", uri);

            shareIntent.setClipData(clip);
            shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        } else {
            List<ResolveInfo> resInfoList =
                    getPackageManager()
                            .queryIntentActivities(shareIntent, PackageManager.MATCH_DEFAULT_ONLY);

            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, uri,
                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                grantUriPermission(packageName, uri,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }

        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0))));
        startActivity(Intent.createChooser(shareIntent, ""));

    } else if (i == R.id.forward) {
        Intent intent = new Intent();
        intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
        setResult(RESULT_OK, intent);
        this.finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 18
Source File: PictureUploadPopUpFragment.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void imageCapture() {

        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (!(getActivity() instanceof MobicomkitUriListener)) {
            Utils.printLog(getContext(),TAG, "Activity must implement MobicomkitUriListener to get image file uri");
            return;
        }

        if (cameraIntent.resolveActivity(getContext().getPackageManager()) != null) {

            Uri capturedImageUri = ((MobicomkitUriListener) getActivity()).getCurrentImageUri();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                ClipData clip =
                        ClipData.newUri(getActivity().getContentResolver(), "a Photo", capturedImageUri);

                cameraIntent.setClipData(clip);
                cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            } else {
                List<ResolveInfo> resInfoList =
                        getActivity().getPackageManager()
                                .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);

                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    getActivity().grantUriPermission(packageName, capturedImageUri,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    getActivity().grantUriPermission(packageName, capturedImageUri,
                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            }
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
            getActivity().startActivityForResult(cameraIntent, ProfileFragment.REQUEST_CODE_TAKE_PHOTO);
        }
    }
 
Example 19
Source File: MessagingBuilder.java    From decorator-wechat with Apache License 2.0 4 votes vote down vote up
@Override public void onReceive(final Context context, final Intent proxy) {
	final PendingIntent reply_action = proxy.getParcelableExtra(EXTRA_REPLY_ACTION);
	final String result_key = proxy.getStringExtra(EXTRA_RESULT_KEY), reply_prefix = proxy.getStringExtra(EXTRA_REPLY_PREFIX);
	final Uri data = proxy.getData(); final Bundle results = RemoteInput.getResultsFromIntent(proxy);
	final CharSequence input = results != null ? results.getCharSequence(result_key) : null;
	if (data == null || reply_action == null || result_key == null || input == null) return;	// Should never happen

	final String key = data.getSchemeSpecificPart(), original_key = proxy.getStringExtra(EXTRA_ORIGINAL_KEY);
	if (BuildConfig.DEBUG && "debug".equals(input.toString())) {
		final Conversation conversation = mController.getConversation(proxy.getIntExtra(EXTRA_CONVERSATION_ID, 0));
		if (conversation != null) showDebugNotification(conversation, "Type: " + conversation.typeToString());
		mController.recastNotification(original_key != null ? original_key : key, null);
		return;
	}
	final CharSequence text;
	if (reply_prefix != null) {
		text = reply_prefix + input;
		results.putCharSequence(result_key, text);
		RemoteInput.addResultsToIntent(new RemoteInput[]{ new RemoteInput.Builder(result_key).build() }, proxy, results);
	} else text = input;
	final ArrayList<CharSequence> history = SDK_INT >= N ? proxy.getCharSequenceArrayListExtra(EXTRA_REMOTE_INPUT_HISTORY) : null;
	try {
		final Intent input_data = addTargetPackageAndWakeUp(reply_action);
		input_data.setClipData(proxy.getClipData());

		reply_action.send(mContext, 0, input_data, (pendingIntent, intent, _result_code, _result_data, _result_extras) -> {
			if (BuildConfig.DEBUG) Log.d(TAG, "Reply sent: " + intent.toUri(0));
			if (SDK_INT >= N) {
				final Bundle addition = new Bundle(); final CharSequence[] inputs;
				final boolean to_current_user = Process.myUserHandle().equals(pendingIntent.getCreatorUserHandle());
				if (to_current_user && context.getPackageManager().queryBroadcastReceivers(intent, 0).isEmpty()) {
					inputs = new CharSequence[] { context.getString(R.string.wechat_with_no_reply_receiver) };
				} else if (history != null) {
					history.add(0, text);
					inputs = history.toArray(new CharSequence[0]);
				} else inputs = new CharSequence[] { text };
				addition.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, inputs);
				mController.recastNotification(original_key != null ? original_key : key, addition);
			}
			markRead(key);
		}, null);
	} catch (final PendingIntent.CanceledException e) {
		Log.w(TAG, "Reply action is already cancelled: " + key);
		abortBroadcast();
	}
}
 
Example 20
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void showVideoCapture() {

        try {
            Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "VID_" + timeStamp + "_" + ".mp4";

            mediaFile = FileClientService.getFilePath(imageFileName, getApplicationContext(), "video/mp4");

            videoFileUri = ALFileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", mediaFile);

            videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoFileUri);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                ClipData clip =
                        ClipData.newUri(getContentResolver(), "a Video", videoFileUri);

                videoIntent.setClipData(clip);
                videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            } else {
                List<ResolveInfo> resInfoList =
                        getPackageManager()
                                .queryIntentActivities(videoIntent, PackageManager.MATCH_DEFAULT_ONLY);

                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    grantUriPermission(packageName, videoFileUri,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    grantUriPermission(packageName, videoFileUri,
                            Intent.FLAG_GRANT_READ_URI_PERMISSION);

                }
            }

            if (videoIntent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
                if (mediaFile != null) {
                    videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                    startActivityForResult(videoIntent, MultimediaOptionFragment.REQUEST_CODE_CAPTURE_VIDEO_ACTIVITY);
                }
            }

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

    }