Google Play Store is missing (Firebase Authentication) - java

I'm beginner for using the Firebase. Currently, I'm trying to do the Firebase Authentication and learnt it from Youtube
(https://www.youtube.com/watch?v=oi-UAwiBigQ&index=9&list=PLGCjwl1RrtcTXrWuRTa59RyRmQ4OedWrt)
but it shows me
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/GooglePlayServicesUtil: Google Play Store is missing.
Here is my code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".FireApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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=".AccountActivity"></activity>
</application>
FireApp.java
package com.google.firebasetester;
import android.app.Application;
import com.firebase.client.Firebase;
public class FireApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this);
}
}
MainActivity.java
package com.google.firebasetester;
import android.accounts.Account;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import java.util.ArrayList;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
private EditText mEmailField;
private EditText mPasswordField;
private Button mLoginBtn;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//FirebaseAuth setup
mAuth=FirebaseAuth.getInstance();
mEmailField = (EditText) findViewById(R.id.emailField);
mPasswordField = (EditText) findViewById(R.id.passwordField);
mLoginBtn = (Button) findViewById(R.id.loginBtn);
mAuthListener =new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
//if equal to null means user have not login, cannot find any user
//if(firebaseAuth.getCurrentUser()==null)
//user has login
if(firebaseAuth.getCurrentUser()!=null)
{
startActivity(new Intent(MainActivity.this, AccountActivity.class));
}
}
};
mLoginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//click when user click on login button
startSignIn();
}
}
);
}
#Override
protected void onStart()
{
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
private void startSignIn()
{
String email=mEmailField.getText().toString();
String password=mPasswordField.getText().toString();
//to make sure user not blank the field
if(TextUtils.isEmpty(email)||TextUtils.isEmpty(password)) {
Toast.makeText(MainActivity.this, "Fields are empty.", Toast.LENGTH_LONG).show();
}
else
{
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//user not successful login
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Sign in Problem", Toast.LENGTH_LONG).show();
}
}
});
}
}
}
AccountActivity.java
package com.google.firebasetester;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class AccountActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account);
}
}
activity_account.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_account"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.google.firebasetester.AccountActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Account"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="184dp"
android:id="#+id/editText" />
</RelativeLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.google.firebasetester.MainActivity"
android:padding="20dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_below="#+id/emailField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="61dp"
android:id="#+id/passwordField"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Password" />
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/passwordField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="110dp"
android:layout_marginStart="110dp"
android:layout_marginTop="31dp"
android:id="#+id/loginBtn" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailField"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Email" />
</RelativeLayout>
build.gradle(Project:FirebaseTester)
// 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.2.2'
classpath 'com.google.gms:google-services:3.0.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
}
build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.google.firebasetester"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by #Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
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:24.2.1'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-crash:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.firebase:firebase-client-android:2.5.2'
compile 'com.google.firebase:firebase-core:9.8.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Android Project
Please help me solve the problem. Thank you!

I had as well the same problem. I've run the application every time on the emulator, were the error occurs. After I run it on a real device, the problem was solved and the login works without any errors.
My tip, try to run it on a real device.

I believe it's because your emulator doesn't have an updated version of Google Play Services. Run the application on your physical phone as GPS updates automatically on that. It might also be because Google Play Services isn't on you emulator.

Related

Test Banner Ad doesn't show

I'm trying to load a banner Ad just for practice. But the ad doesn't show up.
-xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</LinearLayout>
I filled the ads:adUnitId with the test banner unit Id from here
-MainActivity.java
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.RequestConfiguration;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import java.util.Arrays;
import java.util.List;
import static com.google.android.gms.ads.MobileAds.initialize;
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(#NonNull #org.jetbrains.annotations.NotNull InitializationStatus initializationStatus) {
}
});
/*
List<String> testDeviceIds = Arrays.asList("")
RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);*/
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
}
}
The annotated part is one solution I found from google but I couldn't get the message like below so I couldn't fill it.
I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231"))
to get test ads on this device."
-build.gradle(:app)
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.***"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-ads:21.5.0'
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
-build.gradle(:project)
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
-Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="***">
<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/Theme.***">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="***"/>
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I filled the android:value="***" with the app id which I made at AdMob.
There is no error in running app, but the Ad doesn't show up. At logcat I get a message below
I/Ads: Ad failed to load : 0
Also I get an error below
E/DynamiteModule: Failed to load IDynamiteLoader from GmsCore: Application package com.google.android.gms not found
How should I solve this problem? Sorry for duplicated or unnecessary codes.
Add this to your manifest
<uses-permission android:name="android.permission.INTERNET"/>
And also this
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />

Getting error 'Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' ON andoid app

Here is my layout
ProfileDisplay.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Profiledisplay">
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorPrimaryDark"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profilimg"
android:layout_width="160dp"
android:elevation="20dp"
android:layout_height="160dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
app:civ_border_width="2dp"
android:src="#drawable/progileicon"
app:civ_border_color="#FF000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26dp"
android:textColor="#color/white"
android:text="mailid#mail.com"
android:id="#+id/mailid"
android:layout_centerHorizontal="true"
android:layout_marginTop="220dp"
android:textStyle="bold"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:id="#+id/name1"
android:textColor="#color/white"
android:layout_marginTop="260dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bloggerorweiter"
android:textSize="20dp"
android:textColor="#color/white"
android:layout_marginTop="280dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="Blogger or Writer"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="#+id/City"
android:textColor="#color/white"
android:layout_marginTop="300dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="City"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="#+id/state"
android:textColor="#color/white"
android:layout_marginTop="320dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="State"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="#+id/Country"
android:textColor="#color/white"
android:layout_marginTop="340dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="Country"
/>
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation"
android:background="#97145C"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/nav_items"
app:headerLayout="#layout/header">
</com.google.android.material.navigation.NavigationView>
ProfileDisplay.java
package com.example.myapplication;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.media.Image;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import org.w3c.dom.Text;
import java.util.concurrent.ExecutionException;
public class Profiledisplay extends AppCompatActivity {
NavigationView navigationView;
ImageView imgview;
FirebaseAuth mauth;
String currentuserID;
private DatabaseReference userref1;
TextView name,country,mailid,city,state,blog_writer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imgview=findViewById(R.id.profilimg);
name=(TextView) findViewById(R.id.name1);
country=(TextView)findViewById(R.id.Country);
mailid=(TextView)findViewById(R.id.mailid);
city=(TextView)findViewById(R.id.City);
state=(TextView)findViewById(R.id.state);
mauth=FirebaseAuth.getInstance();
blog_writer=(TextView)findViewById(R.id.bloggerorweiter);
currentuserID=mauth.getCurrentUser().getUid();
userref1 = FirebaseDatabase.getInstance().getReference().child("Users");
try{
userref1.child(currentuserID).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
if(dataSnapshot.hasChild("username")){
String fullname1 = dataSnapshot.child("username").getValue().toString();
**name.setText("123456");**
}
if(dataSnapshot.hasChild("urlimage")){
String imageurl=dataSnapshot.child("urlimage").getValue().toString();
Glide.with(getApplicationContext()).load(imageurl).into(imgview);
}else{
Toast.makeText(Profiledisplay.this, "username or profile not exist",
Toast.LENGTH_SHORT).show();
}
String Email="gaakash149#gmail.com";
mailid.setText(Email);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});}
catch(Exception e){
}
setContentView(R.layout.activity_profiledisplay);
navigationView=findViewById(R.id.navigation);
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.home:
Toast.makeText(Profiledisplay.this, "CLicked Home", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),Home.class));
break;
case R.id.Profile:
Toast.makeText(Profiledisplay.this, "CLicked profile",Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),Profiledisplay.class));
break;
case R.id.Post:
Toast.makeText(Profiledisplay.this, "CLicked Post", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),forgotpass.class));
break;
}
return false;
}
});
}
}
error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 25982
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.myapplication.Profiledisplay$1.onDataChange(Profiledisplay.java:51)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##16.0.4:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##16.0.4:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##16.0.4:55)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:7055)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
I got this error every time when I am trying to do SetText() method.
build.gradel file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion '24.0.2'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
implementation 'com.google.android.material:material:1.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.makeramen:roundedimageview:2.3.0'
}
apply plugin: 'com.google.gms.google-services'
You need to setContentView before calling findViewbyID.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profiledisplay); // move setContentView here
imgview=findViewById(R.id.profilimg);
name=(TextView) findViewById(R.id.name1);
....
Your problem is that the view was null when you were trying to finditbyid.
Update
In other words:
setContentView before trying to get reference to the view:
Focus here setContentView(R.layout.activity_profiledisplay);
Make sure that there is a TextView named name1 in activity_profiledisplay.xml
Your Java Activity XML file not match with same Activity.
setContentView(R.layout.********);//here your matching activity.*
Like when u create new activity , MainActivity its xml file name is activity_main...
Use Binding Easy To Understand ...

Android WebView can't display both video tags on WebRTC Peer connection

I've created a Webview on android, with all required permissions on Manifest, and then I tried to display a site with a WebRTC peer connection sample. But it can't display both videos. It shows only the caller and not the recipients.
Android Screen Preview
website in WebView: https://webrtc.github.io/samples/src/content/peerconnection/pc1/
Device: samsung SM-T280
Android: 5.1.1
API: 22
ABI: armeabi-v7a
Play Store:
Android System WebView: Version 73.0.3683.90
Module gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.webview"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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'
}
Project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
MainActivity.java:
package com.example.webview;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
protected WebView webView;
protected Button button;
protected WebSettings settings;
#Override
#SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.web1);
settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setMinimumFontSize(10);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setWebChromeClient(new WebChromeClient() {
#Override
public void onPermissionRequest(final PermissionRequest request) {
request.grant(request.getResources());
}
});
webView.reload();
webView.loadUrl("https://webrtc.github.io/samples/src/content/peerconnection/pc1/");
button = findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
webView.reload();
}
});
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Refresh"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<WebView
android:id="#+id/web1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
</WebView>
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml:
<?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.example.webview">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<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"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I expect both video tags to display the stream.
setting mediaPlaybackRequiresUserGesture as false fixed the issue for me.
settings.mediaPlaybackRequiresUserGesture=false
Just a minor correction, it is -
settings.setMediaPlaybackRequiresUserGesture(false);
and not really -
settings.mediaPlaybackRequiresUserGesture=false;

Android Studio App don't work on Lollipop or KitKat only on 6.0

The App shows the text from a Url. I used Jsoup for this project and the app works very good on devices with API 23 but I would like to support devices from KitKat and Lollipop too. The Buttons and the TextViews work but the internet text is not there.
I hope somebody can help me....
This is my project's build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.schlauies.supertext"
minSdkVersion 15
targetSdkVersion 24
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(include: ['*.jar'], dir: 'libs')
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:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'org.jsoup:jsoup:1.10.2'
}
This is the XMl File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.schlauies.supertext.MainActivity">
<TextView
android:id="#+id/tx1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="TextView" />
<Button
android:id="#+id/but1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="95dp"
android:text="Button" />
</RelativeLayout>
And this is the Java code:
package com.schlauies.supertext;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
//import orgs.Document;
public class MainActivity extends AppCompatActivity {
TextView texx ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
texx =(TextView)findViewById(R.id.tx1);
Button but = (Button) findViewById(R.id.but1);
but.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new doit().execute();
}
});
}
public class doit extends AsyncTask<Void,Void,Void> {
String words = "";
#Override
protected Void doInBackground(Void... params) {
try {
Document doc = Jsoup.connect("http://vertretung.esy.es/gust.txt").get();
words = doc.text();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
texx.setText(words);
}
}
}
If somebody had questions please ask :)
You want to add this permission in Manifest file
<uses-permission android:name="android.permission.INTERNET"/>

why activity_main.xml is not showing when application running

I am developing the simple app. In this project all hidden API of android-23 is open.when i am simple show the button on layout so, it is show only white screen.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.himanshusrivastava.ethernetlollipop.MainActivity"
android:background="#color/colorPrimaryDark">
<Button
android:text="check ethernet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="100dp"
android:layout_marginStart="100dp"
android:layout_marginTop="35dp"
android:id="#+id/button" />
</RelativeLayout>
MainActivity.java
package com.example.himanshusrivastava.ethernetlollipop;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity{
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Ethernet is off", Toast.LENGTH_SHORT).show();
}
});
}
}
build.gradle (Ethernetlollipop)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url 'https://dl.bintray.com/anggrayudi/maven/'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// 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
}
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.himanshusrivastava.ethernetlollipop"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguardandroid.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:23.0.2'
testCompile 'junit:junit:4.12'
compile 'com.anggrayudi:android-hidden-api:0.0.5'
}
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.himanshusrivastava.ethernetlollipop">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
</application>
</manifest>

Categories