App Crashes when calling FirebaseInstanceId.getInstance().getToken()) [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
In my MainActivity class, my app crashes when trying to call FirebaseMessaging.getInstance().subscribeToTopic("global"); and Log.i(TAG, "InstanceID token: " + FirebaseInstanceId.getInstance().getToken()); also trying the console in Firebase i cannot receive any notification.
Here is my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPlayServices();
FirebaseMessaging.getInstance().subscribeToTopic("global");
Log.i(TAG, "InstanceID token: " + FirebaseInstanceId.getInstance().getToken());
}
}
Also i wanted to know is it important to subscribe on topics?
Thank you.

My bad, I forgot to do these steps, i already fixed the error. I needed to add apply plugin: 'com.google.gms.google-services' in my app graddle and add classpath 'com.google.gms:google-services:3.0.0' in my project level gradle. It works fine now.

Related

How to prevent url to show in web view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi there I am trying to create app where I am using web view to show my google drive folder but whenever internet got disconnect in between loading the URL at that a msg comes with showing the URL information.
What can I do to prevent showing URL from users.
Is it possible to show some other msg whenever internet goes down on starting or when it goes down on after starting loading.
I have a custom HTML page that will show if something wrong happened when loading the url.
webView.setWebViewClient(new WebViewClient(){
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
switch(errorCode){
case ERROR_HOST_LOOKUP:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ERROR_CONNECT:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ...[IF YOU WANT TO CATCH MORE ERRORS]
}
}
}
Reference: https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedError(android.webkit.WebView,%20int,%20java.lang.String,%20java.lang.String)
Error Code Reference:
https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_AUTHENTICATION
Yes! You can either print the message or redirect the user to some other activity by checking the following method soon after the app gets launches...
DD4YouConfig dd4YouConfig = new DD4YouConfig(context);
if (dd4YouConfig.isInternetConnectivity()) {
//redirect to webview
}
else
{
//call alert dialog stating no internet
}
This is a library function so obviously don't fail to add this line in Gradle
implementation 'in.dd4you.appsconfig:appsconfig:1.3.3'

Why activity name is not getting resolved in Android Studio [duplicate]

This question already has an answer here:
Cannot resolve second_activity Android Studio [duplicate]
(1 answer)
Closed 2 years ago.
I've an activity XML file created under layouts under my package but still it's complains
package com.alen.cybercpm;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class comrade_login extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comrade_login);
}
}
activity_comrade_login comes in RED/ERROR but I've that file in my package.
I've a splash screen as my Main Activity. then this activity is called.
There is nothing seems to be wrong with your code, Just Restart you Android Studio. You will face such kinds of unexpected and silly problems in future so, the best way is to clear caches by Restarting Your Android Studio
change your Class comrade_login to ComradeLoginActivity
Then clean code
After this Rebuild code
Now clean chache and restart
Hope it will help you
Thankew! Happy Coding

How to insert and display an image in Android? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to insert and display an image. But I have some error. Why I have an error at word "with"?
UsersRef.child(currentUserID).addValueEventListener(new ValueEventListener(){
#Override
public void onDataChange(DataSnapshot dataSnapshot){
if(dataSnapshot.exists()){
String image = dataSnapshot.child("Tuition Image").getValue().toString();
Picasso.with(AddAdsActivity.this).load(image).placeholder(R.drawable.camera).into(TuitionImage);
}
}
#Override
public void onCancelled(DatabaseError databaseError){
}
});
Replace this line:
Picasso.with(AddAdsActivity.this).load(image).placeholder(R.drawable.camera).into(TuitionImage);
With this:
Picasso.get().load(image).placeholder(R.drawable.camera).into(TuitionImage);
And that's it.. Your error will be solved.

How do you make a one time "I agree" activity screen for users on your app? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Can you help me figure out how to make it so my app has users check mark an I agree box before my app goes to the main menu? I need it to only show this screen the very first time the user uses the app. I am new to android studio so any help would be appreciated.
Thanks!
You can easily use SharedPreferences to accomplish this. try doing something like:
final String PREF_NAME = "MyPref";
// getting saved preferences
SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments", "First time");
// first time task
runUserAgreements();
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
Then declare a function named runUserAgreements() and run an activity or dialog showing User Agreements and stuff.
EDIT:
I suggest to put above code in a class extending Application
to check firstrun generally not in the default activity:
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
// CODE HERE
}
}
and DO NOT forget to call the class in AndroidManifest.xml:
<application android:name=".MyApp"
android:label="#string/app_name"
.
.
...>
....
</application>
Take a look at the Google's iosched project example, specifically this Activity: Welcome Activity. IMHO it has a pretty good UI design too.

Android App quits if you push a button to go back to MainActivity [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i started creating a Android App with Android Studio. I created a button (and added android:onClick="page2") in the MainActivity that links to a second Activity with the following code in the MainActivity.java:
public void page2 (View view) {
setContentView(R.layout.activity_page2);
}
So far that works well and i can change from the MainActivity to the page2 Activity.
Now i tried to create a Button on page 2 to link back to the MainActivity, but when i start the emulator and click the button the app crashes..
Any suggestions what the problem is? Maybe i have to restart the MainActivity before i can switch back to it?
Thanks for the help :)
You aren't actually starting a new activity, which is why the app quits when you press back from the main activity. To start a new activity on button press implement the onClick method. Something like:
mButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(getActivity(), ActivityToStart.class);
//intent.putExtra(...) depending on your needs
startActivity(intent);
//or startActivityForResult(...) depending on your needs
}
}
View.OnClickListener
Starting Another Activity
You should use an Intent
More information here : http://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent

Categories