public class MainActivity extends Activity implements PermissionRequest.Response{
public static int CAMERA_PREVIEW_RESULT = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new CameraPreviewIntent(this)
.setExportDir(CameraPreviewIntent.Directory.DCIM, "ImgLyExample")
.setExportPrefix("example_")
.setEditorIntent(
new PhotoEditorIntent(this)
.setExportDir(PhotoEditorIntent.Directory.DCIM, "ImgLyExample")
.setExportPrefix("result_")
.destroySourceAfterSave(true)
)
.startActivityForResult(CAMERA_PREVIEW_RESULT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, android.content.Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == CAMERA_PREVIEW_RESULT) {
String path = data.getStringExtra(CameraPreviewActivity.RESULT_IMAGE_PATH);
Toast.makeText(this, "Image Save on: " + path, Toast.LENGTH_LONG).show();
}
}
Hello
I want to edit the above code so that in the result the activity displays the result image along with the file path, can someone please help with this as I am very new to android development.
The github link to this sdk is-
https://github.com/imgly/imgly-sdk-android-demo
v1 of the SDK is deprecated, please use v2 instead. Please see the documentation how to integrate the newest version.
https://github.com/imgly/imgly-sdk-android-demo
Else I'am not sure what you actually want.
Can you please explain, how your app need to perform?
Related
I use InAppUpdater library for Android In App Updates.
For testing I created a simple application with versionCode 3(before this I posted versionCode 2 in the internal test track, but I did not see updates in my application with versionCode 1) and uploaded it in the Google play in a closed track(alpha version). On the Android device I installed versionCode 2.
Code:
public class UpdateActivity extends AppCompatActivity {
private UpdateManager mUpdateManager;
static final int REQUEST_CODE = 781;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update);
TextView txtCurrentVersion = findViewById(R.id.currentVersion);
TextView txtAvailableVersion = findViewById(R.id.availableVersion);
txtCurrentVersion.setText(String.valueOf(BuildConfig.VERSION_CODE));
// Initialize the Update Manager with the Activity and the Update Mode
mUpdateManager = UpdateManager.Builder(this);
// Callback from Available version code
mUpdateManager.getAvailableVersionCode(code -> txtAvailableVersion.setText(String.valueOf(code)));
}
#Override
protected void onResume() {
super.onResume();
// Continue updates when resumed
mUpdateManager.continueUpdate();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.d("MyTag", "Result ok! Result code: " + resultCode);
}
else if(resultCode == RESULT_CANCELED){
Log.d("MyTag", "Result canceled! Result code: " + resultCode);
}
else if(resultCode == ActivityResult.RESULT_IN_APP_UPDATE_FAILED){
Log.d("MyTag", "In app update failed! Result code: " + resultCode);
}
}
}
public void tryToUpdate(View view){
mUpdateManager.mode(UpdateManagerConstant.FLEXIBLE).start();
}
}
After starting, I see that current version = 2, available version = 3, so the app sees the update. Next I click the tryToUpdate button and see the update dialog, click "update", wait, see "An update has just been downloaded", click "restart", see installation activity, after that my application restarts and I see the old version - current version = 2, and this is the problem. Of course, I tried to manually close and open the app but I still see the old version. But if I delete the old version and manually install the new version from Google Play, then all works fine.
So, how can I solve this?
I wanna write a native module for to scan barcode but it too hard for me to figure out a way to handle the result without adding a method to the MainActivity. It's not a good idea to modify the MainActivity such heavily because it's no easy job for application developers who writes javascript to use the module.
For example, if I use ZXing Android Embedded: https://github.com/journeyapps/zxing-android-embedded, I have to add a method to MainActivity to handle the result.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
That makes an issue that any one who uses this module has to modify their MainActivity, which means the module is hard to use. So, any ideas to work it out?
You can just use react-native-rn-zxing:
npm i react-native-rn-zxing
then link it :
react-native link react-native-rn-zxing
And enjoy
I am making a activity whereby i ask the user to load image from various sources and showing the selected image on a imageview in a different activity.
I am able to show the image from the camera and gallery but from dropbox it is showing error.
For Camera and gallery i can even query the uri obtained from
intent.getData()
in the onactivityresult method and obtain the Filepath and accordingly even obtain the bitmap and resize it .
But the same is not working for Dropbox. Kindly update what code to use for Dropbox so that all options start working.
thanks
For Dropbox you will need to use their Android Chooser to choose files from the user's Dropbox account. You will need a Dropbox API key for this. Once you have grabbed the chooser library and your API key it should be fairly easy to implement;
private Button mChooserButton;
private DbxChooser mChooser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChooser = new DbxChooser(APP_KEY);
mChooserButton = (Button) findViewById(R.id.chooser_button);
mChooserButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mChooser.forResultType(DbxChooser.ResultType.PREVIEW_LINK)
.launch(MainActivity.this, DBX_CHOOSER_REQUEST);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == DBX_CHOOSER_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
DbxChooser.Result result = new DbxChooser.Result(data);
Log.d("main", "Link to selected file: " + result.getLink());
// Handle the result
} else {
// Failed or was cancelled by the user.
}
} else if (requestCode == GALLERY) {
// If your request was from the user gallery
Log.d("main", "Link to selected file: " + data.getData());
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
I have an Activity that should handle results from both the Facebook SDK, and from other custom Activities.
Where can I find the requestCodes used by the Facebook SDK, in order to not use the same for my Activities?
I should be able to tell them apart in the onActivityResult using their requestCode so they need to be unique.
Pass the request code in the sdkInitialize call
FacebookSdk.sdkInitialize(context, 1200);
Then
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (FacebookSdk.isFacebookRequestCode(requestCode)) {
//Facebook activity result
//Do your stuff here
//Further you can also check if it's login or Share etc by using
//CallbackManagerImpl as explained by rajath's answer here
if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) {
//login
}
else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Share.toRequestCode()){
//share
}
}
From the docs
isFacebookRequestCode(int)
Returns true if the request code is within the range used by Facebook SDK requests. This does not include request codes that you explicitly set on the dialogs, buttons or LoginManager. The range of request codes that the SDK uses starts at the callbackRequestCodeOffset and continues for the next 100 values.
sdkInitialize(Context, int)
This function initializes the Facebook SDK, the behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible.
public static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
applicationContext The application context
callbackRequestCodeOffset The request code offset that Facebook activities will be called with. Please do not use the range between the value you set and another 100 entries after it in your other requests.
Go to CallbackManagerImpl.RequestCodeOffset. I personally used a piece of code like this to prevent unwanted behaviour.
if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Try this:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
//Log.iClassMethod();
switch(requestCode)
{
case 1:
if (resultCode == Activity.RESULT_OK)
{
// do something ...
}
break;
case ...:
if (resultCode == Activity.RESULT_OK)
{
// do something ...
}
break;
case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE:
{
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
Log.i("Facebook");
}
break;
}
}
Offering an alternative if you're using FB login via LoginButton
Set request code of login button
Use the request code to differentiate activity
private LoginButton mFacebookLoginButton;
private static int RC_FB_SIGN_IN;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button);
mFacebookLoginButton.registerCallback(...)
RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode();
...
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_GP_SIGN_IN) {
...
} else if (requestCode == RC_FB_SIGN_IN) {
Log.i(TAG, "Doing my facebook usual things");
mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
}
}
You can set your own request codes to disambiguate. All the OpenRequest and NewPermissionsRequest classes take a requestCode parameter:
setRequestCode
Adding to Apetroaei Andrei's answer, there are other options available at Facebook SDK's CallbackManagerImpl class:
public enum RequestCodeOffset {
Login(0),
Share(1),
Message(2),
Like(3),
GameRequest(4),
AppGroupCreate(5),
AppGroupJoin(6),
AppInvite(7),
;
These can be accessed by the foll. code:
if (requestCode == CallbackManagerImpl.RequestCodeOffset.Share.toRequestCode()) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
in the lates sdk, (4.4.1), you can manually set the request code by modifying two files in the facebook library:
1) LoginClient.java
public static int getLoginRequestCode() {
//return CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
return [your request code here];
}
2)LoginManager.java
public void registerCallback(
...
((CallbackManagerImpl) callbackManager).registerCallback([your request code here],
new CallbackManagerImpl.Callback() {
#Override
...
}
);
}
I'm working on an app that take picture by calling the Camera Intent. In the next Activity I use the URI of the image that I got and display the image. It works fine.
The problem is when I test in Sony Neo V device (ICS), the image get rotated 90 degrees (this is the screenshot). It doesn't happen when I test in HTC Desire device (Gingerbread) (this is the screenshot).
Here is my code:
Activity 1:
private final int CAMERA_REQUESTCODE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.memberform);
Button photo = (Button) findViewById(R.id.btn_photo);
photo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUESTCODE);
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( requestCode==CAMERA_REQUESTCODE ) {
if ( resultCode==RESULT_OK ) {
GlobalVar.member.setPhotoUri(data.getData());
} else if ( resultCode==RESULT_CANCELED ) {
} else {
Toast.makeText(this, "Unknown onActivityResult resultCode = " + resultCode, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Unknown onActivityResult requestCode = " + requestCode, Toast.LENGTH_SHORT).show();
}
}
Activity 2:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.memberdetail);
ImageView photo = (ImageView) findViewById(R.id.photo);
photo.setImageURI( GlobalVar.member.getPhotoUri() );
}
I've tried to detect if ( ImageView.getWidth()>ImageView.getHeight() ) then rotate90degrees(); but it doesn't work. And I'm hoping there's a general working code (works on any device) that solve this problem because it would be better than making a conditional if.
Any help & explanation would be appreciated. General working code would be greatly appreciated.
Many thanks
There seems to be a bug with other devices as well, not sure if all Samsung devices do it, but quite a few are doing it. I can confirm on my device Samsung infuse.
You may have to query the ContentResolver to get the orientation for each image and see if it needs rotating.