unable to write to firebase database - android

I'm making an app which can write to firebase database on button click.
The app is working on emulator but it's not working on my physical device.
Here's the main activity code:
public class MainActivity extends AppCompatActivity {
private Firebase fled1;
Button on;
Button off;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
on= findViewById(R.id.on);
off= findViewById(R.id.off);
on.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fled1 = new Firebase("https://iotapp-6y3n8.firebaseio.com/");
Firebase fled1Child = fled1.child("S1");
fled1Child.setValue("1");
}
});
off.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fled1 = new Firebase("https://iotapp-6y3n8.firebaseio.com/");
Firebase fled1Child = fled1.child("S1");
fled1Child.setValue("0");
}
});
}
Here's my manifest file I have added all the permissions required:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lalitahuja.iotbutton">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.lalitahuja.iotbutton.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's the build Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.lalitahuja.iotbutton"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
}
apply plugin: 'com.google.gms.google-services'
The error I'm getting:
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 1
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 2
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 3
W/MessengerIpcClient: Received response for unknown request: 3
E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement
E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.
W/MessengerIpcClient: Received response for unknown request: 1
W/MessengerIpcClient: Received response for unknown request: 2

Related

Have three errors relate to expecting an element and unresolved references

[related code for error in MainActivity.kt][2]
I have tried fn+option+return(Mac IOS) for import purpose, but still not working. Same as trying invalidate caches and restart. They are not working!
I just follow the lecture which is given by the professor step by step. The version for the Android studio on my macbook is 3.5.1
Looking for help.
I also met another error. Here is the code for the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment3muyaozhang0882423" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:value="#integer/google_play_services_version" />
<activity android:name=".Floating_label" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" >
</activity>
</application>
</manifest>
The error I met which is sync error:
ERROR: Failed to parse XML in /Users/kitty/Downloads/Assignment2MuyaoZhang0882423/app/src/main/AndroidManifest.xml
org.xml.sax.SAXParseException; systemId: file:/Users/kitty/Downloads/Assignment2MuyaoZhang0882423/app/src/main/AndroidManifest.xml; lineNumber: 23; columnNumber: 4; 元素类型 "manifest" 必须由匹配的结束标记 "" 终止。
Affected Modules: app
The code for app:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.assignment3muyaozhang0882423"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = kotlin_version
targetCompatibility = kotlin_version
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support:design:29.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
code for kt file:
package com.example.assignment3muyaozhang0882423
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.R
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import android.widget.Toast.makeText
class setion2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_setion2)
val usernamestring = text_Person_Name.text
val passwordstring = text_Password.text
val con_btn = (Button) findViewById(R.id.con_btn) as Button
con_btn.isAllCaps = false
con_btn.setOnClickListener {
if (this.usernamestring.isNotEmpty() && this.passwordstring.isNotEmpty())
{
val message =
"User Name: " + usernamestring + "\n" + "Password: " + this.passwordstring
Toast.makeText(this, message, LENGTH_LONG).show()
} else {
Toast.makeText(this, "Please enter valid input", LENGTH_LONG).show()
}
}
}
}
Please check out my reply on your comment too.
Click on the error of text_layout and send the relevant code.
It is LinearLayout.LayoutParams.MATCH_PARENT
the underscore is missing between MATCH and PARENT

Debugger doesn't go into MainActivity

I got strange problem with white screen and debugger not going into MainActivity. It goes into App class, but doesn't fire the onCreate in MainActivity.
However, if I start my app without debug - just run the app, or build app - it goes into MainActivity fine. I can't find anything specific in my app or any info on what it might be
here's manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.something.something">
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher_new"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
here's App :
public class App extends MultiDexApplication {
private static Api api;
private static Retrofit retrofit;
#Override
public void onCreate() {
super.onCreate();
initRetrofit();
initGlobalVars();
}
private static void initRetrofit() {
if (retrofit == null) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new
HttpLoggingInterceptor.Logger() {
#Override public void log(String message) {
Log.d("MyLog", "message: " + message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(20, TimeUnit.SECONDS)
.writeTimeout(50, TimeUnit.SECONDS)
.readTimeout(50, TimeUnit.SECONDS)
.addInterceptor(logging)
.build();
retrofit = new Retrofit.Builder()
.baseUrl(Setup.URL)
.addConverterFactory(ScalarsConverterFactory.create())
.client(okHttpClient)
.build();
api = retrofit.create(Api.class);
}
}
private void initGlobalVars(){
GlobalVariableKeeper.INSTANCE.init(this);
}
public static Api getApi() {
return api;
}
public static Retrofit getRetrofit(){
return retrofit;
}
}
and gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.something.something"
minSdkVersion 21
targetSdkVersion 28
versionCode 27
versionName "0.35"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.billingclient:billing:1.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
}
repositories {
mavenCentral()
}

Manifest merger failed with multiple errors123

When I try to rebuild project, android studio gives the error: I couldn't solve this problem for 2 days please help. What changes should I make?
``Execution failed for task ':app:processDebugManifest'.
I tried all solutions provided for similar problems like this one:
enter link description here
enter link description here
my build gradle
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
//the compression of webp file during build causes problem with FileDescriptor in ContentProvider.
aaptOptions {
noCompress "webp"
}
signingConfigs {
signing_config {
keyAlias 'abc'
keyPassword '123'
}
}
compileSdkVersion 28
defaultConfig {
applicationId "com.whatsapp.fenerstickers"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
def contentProviderAuthority = applicationId + ".stickercontentprovider"
// Creates a placeholder property to use in the manifest.
manifestPlaceholders =
[
onesignal_app_id: 'XXXXXXX',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
[contentProviderAuthority: contentProviderAuthority]
// Adds a new field for the authority to the BuildConfig class.
buildConfigField("String",
"CONTENT_PROVIDER_AUTHORITY",
"\"${contentProviderAuthority}\"")
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
task checkDebug {
doLast {
println("checkDebug")
if (android.defaultConfig.applicationId.startsWith("com.whatsapp")) {
throw new GradleException("applicationId in defaultConfig cannot start with com.whatsapp, please change your applicationId in app/build.gradle");
}
checkApplicationIdInDebug()
}
}
private void checkApplicationIdInDebug() {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ignoreApplicationIdCheck = properties.getProperty('ignoreApplicationIdCheck')
if (ignoreApplicationIdCheck == null) {
} else {
println("application id check ignored")
}
}
task checkRelease {
doLast {
println("checkRelease")
if (android.defaultConfig.applicationId.startsWith("com.example")) {
throw new GradleException("applicationId in defaultConfig cannot start with com.example, please change your applicationId in app/build.gradle");
}
}
}
tasks.whenTaskAdded { task ->
println(task.name)
if (task.name.contains("assembleDebug")) {
task.dependsOn checkDebug
}
if (task.name.contains("assembleRelease")) {
task.dependsOn checkRelease
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.10.0'
implementation 'com.facebook.fresco:animated-webp:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.10.0'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.firebase:firebase-ads:11.8.0'
implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
}
my manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.main.berk">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:allowBackup="false"
android:fullBackupContent="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".EntryActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StickerPackListActivity"
android:label="#string/title_activity_sticker_packs_list" />
<activity
android:name=".StickerPackDetailsActivity"
android:parentActivityName=".StickerPackListActivity"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.main.berk.StickerPackListActivity" />
</activity>
<activity
android:name=".StickerPackInfoActivity"
android:label="#string/title_activity_sticker_pack_info"
android:parentActivityName=".StickerPackDetailsActivity"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.main.berk.StickerPackDetailsActivity" />
</activity>
<provider
android:name=".StickerContentProvider"
android:authorities="${contentProviderAuthority}"
android:enabled="true"
android:exported="true"
android:readPermission="com.whatsapp.sticker.READ" />
</application>
</manifest>
Merging Errors:
Error: Attribute provider#com.main.berk.StickerContentProvider#authorities at AndroidManifest.xml:48:13-62 requires a placeholder substitution but no value for <contentProviderAuthority> is provided. app main manifest (this file), line 47 Error: Validation failed, exiting app main manifest (this file)
You just need to combine multiple array of manifestPlaceholders in one like this
manifestPlaceholders =
[
// WhatsApp Placeholder
contentProviderAuthority: contentProviderAuthority,
onesignal_app_id: 'XXXXXXX',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]

I/CrashlyticsCore: Crashlytics report upload complete but not show in dashboard

I have problem with Fabric. its a test project for find problem and do everything step by step in fabric documents, but i don't know what is mistake. please help me.
My Gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycompany.testtt"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true;
}
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.testtt">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9fd0b323bad2f5dae063288c94fd3a2317faa104"
/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Main Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
// TODO: Move this to where you establish a user session
logUser();
setContentView(R.layout.activity_main);
}
private void logUser() {
// TODO: Use the current user's information
// You can call any combination of these three methods
Crashlytics.setUserIdentifier("12345");
Crashlytics.setUserEmail("user#fabric.io");
Crashlytics.setUserName("Test User");
}
public void forceCrash(View view) {
throw new RuntimeException("This is a crash");
}
After all, and error and testing, but nothing is still displayed on the dashboard.
I do everything step by step from fabric documents.
I have this problem for a few days, and anyway I've tested it, but I still have not gotten a result and does not display anything in the fabric dashboard. ApiKey is correct and I'm sure of it.
(sorry for English)

Firebase android facebook,google,email login interface does not popup

I've watched a tutorial on YouTube about how to integrate Firebase to android applications. Registered Firebase, add my facebook and app info, and add the necessary changes to my app but somehow my main interface which should show login screens does not show up. There is no build errors.
Here are my codes;
My build.gradle inside my app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.bogroup.ucuncuprogram"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
//compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.firebaseui:firebase-ui:0.4.4'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.android.support:animated-vector-drawable:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile 'com.android.support:customtabs:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
//compile 'com.android.support:customtabs:25.2.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
My main java code:
package com.bogroup.ucuncuprogram;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import com.firebase.ui.auth.AuthUI;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity {
private static final int RC_SIGN_IN = 0;
EditText et;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
auth = FirebaseAuth.getInstance();
if(auth.getCurrentUser() != null){
//USER ALREADY SIGNED IN
Log.d("AUTH", auth.getCurrentUser().getEmail());
}else{
startActivityForResult(AuthUI.getInstance()
.createSignInIntentBuilder()
.setProviders(AuthUI.FACEBOOK_PROVIDER,
AuthUI.EMAIL_PROVIDER,
AuthUI.GOOGLE_PROVIDER)
.build(),RC_SIGN_IN);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RC_SIGN_IN){
if(resultCode==RESULT_OK){
//user logged in
Log.d("AUTH", auth.getCurrentUser().getEmail());
}else{
// user not authenticated
Log.d("AUTH", "NOT AUTHENTİCATED");
}
}
}
public void tikla(View v){
if (v.getId()==R.id.button){
Intent intent = new Intent(getApplicationContext(),ikinciekren.class);
CharSequence charlarim = et.getText();
intent.putExtra("anahtar",charlarim);
startActivity(intent);
//
}
/*
else if (v.getId()==R.id.button){
//
}
*/
}
}
My main build.gradle file (not under app)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My android.manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bogroup.ucuncuprogram">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ikinciekren">
<intent-filter>
<action android:name="android.intent.action.IKINCIEKREN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Also added google-services.json file under app and facebook id under in string.xml file
Any help is appreciated. Thanks in advance.
Try changing startActivityForResult() to:
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setProviders(Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()
))
.build(),
RC_SIGN_IN);
To learn more about authentication on Firebase UI library look at:
https://github.com/firebase/FirebaseUI-Android/tree/master/auth

Categories

Resources