Toggle navigation
Toggle navigation
This project
Loading...
Sign in
손장민
/
FirebaseAuth
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
한윤범
2017-10-13 12:35:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9c5ad7c174ba9d5a0e4393f8ab310e85bb3a70fb
9c5ad7c1
1 parent
4d8dd9d9
add permission to access firebase storage
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
7 deletions
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/example/user/firebaseauthdemo/Main2Activity.java
app/src/main/java/com/example/user/firebaseauthdemo/MainActivity.java
app/src/main/java/com/example/user/firebaseauthdemo/PostActivity.java
app/build.gradle
View file @
9c5ad7c
...
...
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android
{
compileSdkVersion
25
buildToolsVersion
"26.0.1"
buildToolsVersion
'25.0.0'
defaultConfig
{
applicationId
"com.example.user.firebaseauthdemo"
minSdkVersion
15
...
...
@@ -28,10 +28,12 @@ dependencies {
compile
'com.android.support:recyclerview-v7:25.3.1'
compile
'com.android.support:cardview-v7:25.3.1'
compile
'com.android.support.constraint:constraint-layout:1.0.2'
compile
'com.google.firebase:firebase-auth:10.2.6'
compile
'com.google.android.gms:play-services-auth:10.2.6'
compile
'com.google.firebase:firebase-database:10.2.6'
compile
'com.google.firebase:firebase-storage:10.2.6'
compile
'com.google.firebase:firebase-auth:11.0.2'
compile
'com.google.firebase:firebase-core:11.0.2'
compile
'com.google.android.gms:play-services-auth:11.0.2'
compile
'com.google.firebase:firebase-database:11.0.2'
compile
'com.google.firebase:firebase-storage:11.0.2'
compile
'com.google.firebase:firebase-crash:11.0.2'
compile
'com.firebaseui:firebase-ui-database:0.4.0'
compile
'com.android.support:design:25.3.1'
testCompile
'junit:junit:4.12'
...
...
app/src/main/AndroidManifest.xml
View file @
9c5ad7c
...
...
@@ -3,6 +3,8 @@
package=
"com.example.user.firebaseauthdemo"
>
<user-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application
android:allowBackup=
"true"
...
...
app/src/main/java/com/example/user/firebaseauthdemo/Main2Activity.java
View file @
9c5ad7c
...
...
@@ -18,6 +18,7 @@ public class Main2Activity extends AppCompatActivity
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main2
);
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
...
...
app/src/main/java/com/example/user/firebaseauthdemo/MainActivity.java
View file @
9c5ad7c
...
...
@@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
...
...
app/src/main/java/com/example/user/firebaseauthdemo/PostActivity.java
View file @
9c5ad7c
package
com
.
example
.
user
.
firebaseauthdemo
;
import
android.Manifest
;
import
android.app.ProgressDialog
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v7.app.AppCompatActivity
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.ImageButton
;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.storage.FirebaseStorage
;
import
com.google.firebase.storage.StorageReference
;
import
com.google.firebase.storage.UploadTask
;
public
class
PostActivity
extends
AppCompatActivity
{
private
ImageButton
mSelectImage
;
private
EditText
mPostTitle
;
private
EditText
mPostDesc
;
private
Button
mSubmitBtn
;
private
Uri
mImageUri
=
null
;
private
static
final
int
GALLARY_REQUEST
=
1
;
private
static
final
int
PERMISSIONS_REQUEST_READ_STORAGE
=
100
;
private
StorageReference
mStorage
;
private
ProgressDialog
mProgress
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]{
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
},
PERMISSIONS_REQUEST_READ_STORAGE
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_post
);
mSelectImage
=
(
ImageButton
)
findViewById
(
R
.
id
.
imageSelect
);
mPostTitle
=
(
EditText
)
findViewById
(
R
.
id
.
titleField
);
mPostDesc
=
(
EditText
)
findViewById
(
R
.
id
.
descField
);
mSubmitBtn
=
(
Button
)
findViewById
(
R
.
id
.
submitBtn
);
mStorage
=
FirebaseStorage
.
getInstance
().
getReference
();
mProgress
=
new
ProgressDialog
(
this
);
mSelectImage
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -28,6 +62,34 @@ public class PostActivity extends AppCompatActivity {
startActivityForResult
(
gallaryIntent
,
GALLARY_REQUEST
);
}
});
mSubmitBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
startPosting
();
}
});
}
private
void
startPosting
()
{
mProgress
.
setMessage
(
"Posting to Blog ... "
);
String
title_val
=
mPostTitle
.
getText
().
toString
().
trim
();
String
desc_val
=
mPostDesc
.
getText
().
toString
().
trim
();
if
(!
TextUtils
.
isEmpty
(
title_val
)
&&
!
TextUtils
.
isEmpty
(
desc_val
)
&&
mImageUri
!=
null
)
{
mProgress
.
show
();
StorageReference
filepath
=
mStorage
.
child
(
"Blog_Images"
).
child
(
mImageUri
.
getLastPathSegment
());
filepath
.
putFile
(
mImageUri
).
addOnSuccessListener
(
new
OnSuccessListener
<
UploadTask
.
TaskSnapshot
>()
{
@Override
public
void
onSuccess
(
UploadTask
.
TaskSnapshot
taskSnapshot
)
{
Uri
downloadUrl
=
taskSnapshot
.
getDownloadUrl
();
mProgress
.
dismiss
();
}
});
}
}
@Override
...
...
@@ -35,8 +97,8 @@ public class PostActivity extends AppCompatActivity {
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
GALLARY_REQUEST
&&
resultCode
==
RESULT_OK
){
Uri
i
mageUri
=
data
.
getData
();
mSelectImage
.
setImageURI
(
i
mageUri
);
mI
mageUri
=
data
.
getData
();
mSelectImage
.
setImageURI
(
mI
mageUri
);
}
}
}
...
...
Please
register
or
login
to post a comment