@@ -44,8 +44,9 @@ public class MainActivity extends AppCompatActivity implements PickiTCallbacks {
44
44
PickiT pickiT ;
45
45
46
46
//Views
47
- Button button_pick ;
47
+ Button button_pick_video , button_pick_image ;
48
48
TextView pickitTv , originalTv , originalTitle , pickitTitle ;
49
+ String videoImageRef = "" ;
49
50
50
51
@ Override
51
52
protected void onCreate (Bundle savedInstanceState ) {
@@ -66,16 +67,28 @@ private void showLongToast(final String msg) {
66
67
}
67
68
68
69
private void init () {
69
- button_pick = findViewById (R .id .button_pick );
70
+ button_pick_video = findViewById (R .id .button_pick_video );
71
+ button_pick_image = findViewById (R .id .button_pick_image );
70
72
pickitTv = findViewById (R .id .pickitTv );
71
73
originalTv = findViewById (R .id .originalTv );
72
74
originalTitle = findViewById (R .id .originalTitle );
73
75
pickitTitle = findViewById (R .id .pickitTitle );
74
76
}
75
77
76
78
private void buttonClickEvent () {
77
- button_pick .setOnClickListener (view -> {
78
- openGallery ();
79
+ button_pick_video .setOnClickListener (view -> {
80
+ videoImageRef = "video" ;
81
+ openGallery ("video" );
82
+
83
+ // Make TextView's invisible
84
+ originalTitle .setVisibility (View .INVISIBLE );
85
+ originalTv .setVisibility (View .INVISIBLE );
86
+ pickitTitle .setVisibility (View .INVISIBLE );
87
+ pickitTv .setVisibility (View .INVISIBLE );
88
+ });
89
+ button_pick_image .setOnClickListener (view -> {
90
+ videoImageRef = "image" ;
91
+ openGallery ("image" );
79
92
80
93
// Make TextView's invisible
81
94
originalTitle .setVisibility (View .INVISIBLE );
@@ -85,24 +98,44 @@ private void buttonClickEvent() {
85
98
});
86
99
}
87
100
88
- private void openGallery () {
101
+ private void openGallery (String videoOrImage ) {
89
102
// first check if permissions was granted
90
103
if (checkSelfPermission ()) {
91
- Intent intent ;
92
- if (Environment .getExternalStorageState ().equals (Environment .MEDIA_MOUNTED )) {
93
- intent = new Intent (Intent .ACTION_PICK , MediaStore .Video .Media .EXTERNAL_CONTENT_URI );
94
- } else {
95
- intent = new Intent (Intent .ACTION_PICK , MediaStore .Video .Media .INTERNAL_CONTENT_URI );
96
- }
97
- // In this example we will set the type to video
98
- intent .setType ("video/*" );
99
- intent .setAction (Intent .ACTION_GET_CONTENT );
100
- intent .putExtra ("return-data" , true );
101
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
102
- intent .putExtra (Intent .EXTRA_ALLOW_MULTIPLE , true );
104
+ if (videoImageRef .equals ("video" )) {
105
+ videoImageRef = "" ;
106
+ Intent intent ;
107
+ if (Environment .getExternalStorageState ().equals (Environment .MEDIA_MOUNTED )) {
108
+ intent = new Intent (Intent .ACTION_PICK , MediaStore .Video .Media .EXTERNAL_CONTENT_URI );
109
+ } else {
110
+ intent = new Intent (Intent .ACTION_PICK , MediaStore .Video .Media .INTERNAL_CONTENT_URI );
111
+ }
112
+ // In this example we will set the type to video
113
+ intent .setType ("video/*" );
114
+ intent .setAction (Intent .ACTION_GET_CONTENT );
115
+ intent .putExtra ("return-data" , true );
116
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
117
+ intent .putExtra (Intent .EXTRA_ALLOW_MULTIPLE , true );
118
+ }
119
+ intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
120
+ activityResultLauncher .launch (intent );
121
+ }else {
122
+ videoImageRef = "" ;
123
+ Intent intent ;
124
+ if (Environment .getExternalStorageState ().equals (Environment .MEDIA_MOUNTED )) {
125
+ intent = new Intent (Intent .ACTION_PICK , MediaStore .Images .Media .EXTERNAL_CONTENT_URI );
126
+ } else {
127
+ intent = new Intent (Intent .ACTION_PICK , MediaStore .Images .Media .INTERNAL_CONTENT_URI );
128
+ }
129
+ // In this example we will set the type to video
130
+ intent .setType ("image/*" );
131
+ intent .setAction (Intent .ACTION_GET_CONTENT );
132
+ intent .putExtra ("return-data" , true );
133
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
134
+ intent .putExtra (Intent .EXTRA_ALLOW_MULTIPLE , true );
135
+ }
136
+ intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
137
+ activityResultLauncher .launch (intent );
103
138
}
104
- intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
105
- activityResultLauncher .launch (intent );
106
139
}
107
140
}
108
141
@@ -122,7 +155,11 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
122
155
if (requestCode == PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE ) {
123
156
if (grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
124
157
// Permissions was granted, open the gallery
125
- openGallery ();
158
+ if (videoImageRef .equals ("video" )) {
159
+ openGallery ("video" );
160
+ }else {
161
+ openGallery ("image" );
162
+ }
126
163
}
127
164
// Permissions was not granted
128
165
else {
0 commit comments