I have following code to open the storage access framework:
private void startDialog()
{
Intent intent= new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
startActivityForResult(intent, 1);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData)
{
super.onActivityResult(requestCode, resultCode, resultData);
}
But in in the SAF, I can select all places on my device. How can I open directly only my Google Drive Account? One way maybe is of the SAF and another way is over the google drive rest api v3. I can authenticate me with them, but i don't know how to open files with the api. With api v2 i could open file via: Drive.DriveApi but the DriveApi is deprecated.
Related
I'm using the following code to record the camera in Android. How can I change the default codec (the default is H264) here?
private Uri fileUri;
//...
private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
// set video quality
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file
// start the video capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}
// ...
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE && resultCode == RESULT_OK) {
// play the video given the global fileUri
}
You cannot achieve this with ACTION_VIDEO_CAPTURE intent. You have to open the camera in your app and handle recording video by yourself. The official example using CameraX library are a good starting point.
To control the codec, you need an extra step. You can borrow from this answer, which enforces h264 – but you are free to choose MediaCodec.createEncoderByType() the way you like.
How do i get the response from stripe with the new Activity Result Api? I create a new card and i want to attach it to a stripe account. To do that i have to use the confirm setup intent and wait for the answer from stripe. But how do i register this one with the new Api? This is my code and but the onActivityResult has been deprecated now. I know how to use it for picking images or making phone calls and other that can use the launch function of the register activity. I don't want to do this on the server side because if the card needs 3D secure webview stripe handles that automatically.
ConfirmSetupIntentParams confirmParams = ConfirmSetupIntentParams
.create(paymentMethodParams, clientSecret);
stripe.confirmSetupIntent(this, confirmParams);
#Override
public void onActivityResult(int requestCode, int resultCode, #org.jetbrains.annotations.Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
stripe.onSetupResult(requestCode, data, new ApiResultCallback<SetupIntentResult>() {
I tried to get path from
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Complete action using"), 2);
But I did't get path from Marshamallow, I can get path from lollipop.
How I can get file path from internal storage?
I think you will have to use file provider for that.
Refer this.
https://developer.android.com/reference/android/support/v4/content/FileProvider
When you start an activity using startActivityForResult, the calling activity will get the results (if any) in onActivityResult. You should override that method in your calling activity...
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
}
This will method will get called as soon as the results are returned from the activity started by startActivityForResult. You can use the requestCode parameter to match (or filter out) the results you are expecting. In your case, you should check that requestCode is equal to 2 which is the value you provided in startActivityForResult.
If the requestCode is equal to 2, then you know that you need to process a PDF file. The intent parameter "could" have the path of that PDF file...
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if(requestCode == 2 && data != null){
//This is the uri to the file (which could be null)
Uri uri = data.getData();
if(uri != null){
Log.i("LOG_TAG", String.format("uri path = %s", uri));
}
}
}
Now, to browse and select files you will do it the following way (Android Kitkat and above...I think)...
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
startActivityForResult(intent, SELECT_FILE_REQUEST_CODE);
Then you receive the selected PDF uri as mentioned above
UPI (Unified Payment Interface) is a payment interface for Indian banks.
In UPI transactions are links. Just like bitcoin transactions are messages
Those links are passed to UPI payment apps and the payer has to login to the app and click the pay button.
Our app has to start an intent and pass link to the UPI payment app and after payer clicks the pay button we need to call onActivityResult.
I dont know anything about android development in java.
I use python kivy for android development. I want to know what should my onActivityResult should do.
Sample code :
UPI App Deep linking using Intent - inconsistent and buggy behavior
I can use java code in python using pyjnius.
Some reference link:
https://blog.deazzle.in/enable-upi-payments-in-your-app-without-the-need-to-integrate-with-a-bank-c911019f3b2d
you have not any need to do it manually. I have developed a library for it.
Just have to do a simple process.
final EasyUpiPayment easyUpiPayment = new EasyUpiPayment.Builder()
.with(this)
.setPayeeVpa("EXAMPLE#VPA")
.setPayeeName("PAYEE_NAME")
.setTransactionId("UNIQUE_TRANSACTION_ID")
.setTransactionRefId("UNIQUE_TRANSACTION_REF_ID")
.setDescription("DESCRIPTION_OR_SMALL_NOT")
.setAmount("AMOUNT_IN_DECIMAL_XX.XX")
.build();
easyUpiPayment.startPayment();
For more info, you can visit below site.
https://github.com/PatilShreyas/EasyUpiPayment-Android
Activity A:
Intent start = new Intent(MainActivity.this, PurchaseActivity.class);
startActivityForResult(start, 1);
And add this result listener:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
//payment was successful
}else if (resultCode == RESULT_CANCELED) {
//payment was canceled
}
}
}
And Activity B:
If payment was successful:
setResult(RESULT_OK, new Intent());
finish();
or if it was canceled:
setResult(RESULT_CANCELED, new Intent());
finish();
When I click a button,show a file browser,I can choose a folder and return it's path.I get this path to copy file to that path.
But I have no idea of How I could implement this.
I have yet looking for this question in Stackoverflow but I haven't find a clear answer to my question.
I saw some libary of filebrowserview like "https://github.com/psaravan/FileBrowserView",but not work.
Use intent for that!
First start start activity for result like this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
Override this method in your activity, it will get called when activity you just started returns. You can handle result codes such as canceled or successful.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String Fpath = data.getDataString();
//TODO handle your request here
super.onActivityResult(requestCode, resultCode, data);
}
Another approach is to use library such as NoNonsense-FilePicker.