Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Tools
TNEF Extractor
Commits
4721ab1d
Verified
Commit
4721ab1d
authored
Sep 16, 2019
by
FabioWidmer
Browse files
Add extraction dialog
parent
5a19a357
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/starapps/tools/tnefextractor/TNEFActivity.java
View file @
4721ab1d
...
...
@@ -4,7 +4,9 @@ import androidx.appcompat.app.AppCompatActivity;
import
androidx.documentfile.provider.DocumentFile
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.ContentResolver
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
...
...
@@ -21,9 +23,12 @@ import net.freeutils.tnef.TNEFUtils;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
public
class
TNEFActivity
extends
AppCompatActivity
{
private
static
final
int
REQUEST_CODE_BROWSE_FOLDER
=
1
;
private
ArrayList
<
CharSequence
>
attachmentNames
=
new
ArrayList
<>();
private
ArrayList
<
Uri
>
attachmentFiles
=
new
ArrayList
<>();
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -72,18 +77,37 @@ public class TNEFActivity extends AppCompatActivity {
message
=
new
Message
(
tnefInputStream
);
extractAttachmentsTo
(
message
,
folderFile
);
Toast
.
makeText
(
getApplicationContext
(),
getString
(
R
.
string
.
extraction_succeeded
),
Toast
.
LENGTH_LONG
).
show
();
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setTitle
(
R
.
string
.
extraction_dialog_title
)
.
setCancelable
(
true
)
.
setOnCancelListener
(
new
DialogInterface
.
OnCancelListener
()
{
public
void
onCancel
(
DialogInterface
dialogInterface
)
{
finish
();
}
})
.
setItems
(
attachmentNames
.
toArray
(
new
CharSequence
[
0
]),
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
intent
.
setDataAndType
(
attachmentFiles
.
get
(
which
),
getMimeType
(
attachmentNames
.
get
(
which
).
toString
()));
startActivity
(
intent
);
finish
();
}
}).
show
();
}
catch
(
IOException
e
)
{
Toast
.
makeText
(
getApplicationContext
(),
getString
(
R
.
string
.
extraction_failed_all
),
Toast
.
LENGTH_LONG
).
show
();
finish
();
}
finally
{
try
{
TNEFUtils
.
closeAll
(
message
,
tnefInputStream
,
inputStream
);
}
catch
(
IOException
ignored
)
{
}
}
}
else
{
finish
();
}
finish
();
}
private
void
extractAttachmentsTo
(
Message
message
,
DocumentFile
folder
)
{
...
...
@@ -103,6 +127,8 @@ public class TNEFActivity extends AppCompatActivity {
if
(
file
!=
null
)
{
attachment
.
writeTo
(
contentResolver
.
openOutputStream
(
file
.
getUri
()));
attachmentNames
.
add
(
filename
);
attachmentFiles
.
add
(
file
.
getUri
());
}
}
catch
(
IOException
e
)
{
Toast
.
makeText
(
getApplicationContext
(),
getString
(
R
.
string
.
extraction_failed_single
,
filename
),
Toast
.
LENGTH_LONG
).
show
();
...
...
app/src/main/res/values/strings.xml
View file @
4721ab1d
<resources>
<string
name=
"app_name"
>
TNEF Extractor
</string>
<string
name=
"extraction_dialog_title"
>
Extracted Attachments
</string>
<string
name=
"extraction_failed_all"
>
Failed to extract file.
</string>
<string
name=
"extraction_failed_single"
>
Failed to extract attachment %1$s.
</string>
<string
name=
"extraction_succeeded"
>
File extracted successfully.
</string>
</resources>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment