Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Certified Android App Developer

Roopesh Naidu

NA
Simplilearn Support
Trainer
FCM Notification are not working while my app in background
Manifest bellow

<service android:name=".MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter></service><meta-dataandroid:name="com.google.firebase.messaging.default_notification_icon"android:resource="@mipmap/ic_launcher_round" /><meta-dataandroid:name="com.google.firebase.messaging.default_notification_color"android:resource="@color/colorAccent" />

.MyFirebaseMessagingService.java bellow

package com.prince.senpleweb;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service
;import android.app.TaskStackBuilder;
import android.content.Context;import android.content.Intent;import android.media.RingtoneManager;import android.net.Uri;import android.os.Build;import android.os.Bundle;import android.os.IBinder;import android.support.annotation.Nullable;import android.support.v4.app.NotificationCompat;import android.support.v4.app.NotificationManagerCompat;import android.util.Log;import com.google.firebase.messaging.FirebaseMessagingService;import com.google.firebase.messaging.RemoteMessage;public class MyFirebaseMessagingService extends FirebaseMessagingService {
String TAG="background";@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {
String title = remoteMessage.getNotification().getTitle();String message = remoteMessage.getNotification().getBody();Log.d(TAG, "onMessageReceived: Message Received: \n" +
"Title: " + title + "\n" +
"Message: " + message);sendNotification(title,message);}

private void sendNotification(String title,String messageBody) {
Intent intent = new Intent(this, Main2Activity.class);intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);Bundle b=new Bundle();b.putString("title",title);b.putString("massage",messageBody);intent.putExtras(b);TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);stackBuilder.addParentStack(Main2Activity.class);stackBuilder.addNextIntent(intent);PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(messageBody))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(resultPendingIntent);NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());}
}
 
Last edited by a moderator:

DeshDeep Singh

Well-Known Member
Simplilearn Support
Alumni
To set up Android Studio on Windows:

  1. Launch the .exe file you downloaded.
  2. Follow the setup wizard to install Android Studio and any necessary SDK tools.
    On some Windows systems, the launcher script does not find where the JDK is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.

    Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for exampleC:\Program Files\Java\jdk1.7.0_21.


The individual tools and other SDK packages used by Android Studio are installed in a separate directory. If you need to access the tools directly, use a terminal to navigate to the location where they are installed. For example:

\Users\<user>\sdk\
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hi ,

I know how an android developer feels when the android studio is opened and the later when the built app functions the way we wanted. Here a Tip where you can use free source emulator instead of Android Studio Emulator:

Excited? That's great!, So here is what you have to do :
  1. Install BlueStacks.
  2. Turn it ON once you think that your code is ready to perform the operation.
  3. While selecting the Emulator while running the code, Select the Opened Emulator.
That's it. There you go! your error free App will be installed in Bluestacks and ready to function.
 

Vipin_41

Member
Alumni
my XML Layout file is not completeing
android:background="@android:color/" for options , how to fix it .

<?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"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:background="@android:color/"tools:context="com.example.eviptri.helloword.SecondActivity">
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hey Vipin,


Kindly follow the below steps :

  1. Go to File once you open the Android Studio.
  2. Select Invalidate Caches/restart.

You Android Studio will restart with the caches being cleared. Kindly save the Assets before you perform the above steps.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Other than the Technical Advantages, Let us know Why Android is generally considered as important :

1. It supports different platforms like - Linux, Mac OS, Windows.
2. Database programming has been imported - Here SQLite has been used.
3. Easy to use and access.
4. A great User Interface with Touch options.
5. Know the information about world with just a click.

To know more, Keep Visiting.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hello,

To know facts about Android Studio (AS) :
  1. You can connect your Physical device and install Apps instead of AVD. ( Check this : https://developer.android.com/studio/run/oem-usb.html )
  2. If your Graddle asks you to install the updated version than do it rather than setting the API level to lower level to avoid other conflicts.
  3. Set the Environment Variables(EV) in your Local system.Sometimes , AS accepts it by default but most of the time it asks to set the EV.
  4. For the new users, Always use the API 20 and more to perform functionally better.
  5. Do not Run Graddle offline at the beginning until the first execution of the Test App in Emulator. Connect your System to internet for resolving dependencies.
New User ? and confused on what type of App you should Build ?
Refer the link mentioned below

https://www.quora.com/What-Android-app-can-I-build

I hope it helps! Keep visiting for more information.
 

Hitesh_39

New Member
Alumni
Hi,

When i create a new project in Android Studio with Basic Activity, i am not able to view the rendered layout for my content_main.xml and activity_main.xml. In the Preview box, i am getting the below error

Rendering Problems
The following classes could not be found:
- android.support.design.widget.AppBarLayout (Fix Build Path, Create Class)
- android.support.design.widget.CoordinatorLayout (Fix Build Path, Create Class)

Tip: Try to build the project

The surrounding layout (@layout/activity_main) did not actually include this layout. Remove tools:showIn-... from the root tag

After this, it builds the project automatically and this error is gone, but i don't see the rendered device. Please help
 

DEEP BATRA

New Member
Alumni
i tried upgrading my pc but still im unable to run the emulator.

please suggest complete steps and settings for debugging.
 

Rakesh Deshpande

Moderator
Simplilearn Support
i tried upgrading my pc but still im unable to run the emulator.

please suggest complete steps and settings for debugging.
Hi Deep,

I have mailed you a file regarding the common errors and the solutions. Hope it helps you! Keep us posted here for further queries.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hi,

When i create a new project in Android Studio with Basic Activity, i am not able to view the rendered layout for my content_main.xml and activity_main.xml. In the Preview box, i am getting the below error

Rendering Problems
The following classes could not be found:
- android.support.design.widget.AppBarLayout (Fix Build Path, Create Class)
- android.support.design.widget.CoordinatorLayout (Fix Build Path, Create Class)

Tip: Try to build the project

The surrounding layout (@layout/activity_main) did not actually include this layout. Remove tools:showIn-... from the root tag

After this, it builds the project automatically and this error is gone, but i don't see the rendered device. Please help
Hi Hitesh,

Kindly download the x86 Atom Images and other complete files related to your API from SDK Manager -> Stand Alone SDK and once it is done, Clear the Caches and restart the studio. File-> Invalidate Cache/Restart.

Try this and keep us posted regarding this.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hello,

Every Beginner in Android App Development must have encountered the general/common errors like Rendering format mismatch etc. Hence in order to resolve the basic errors we have prepared a document where you can download and go through. Hope it Helps! Keep visiting the site for more updated information.
 

Attachments

  • Android Error resolution Guide.pdf
    592.9 KB · Views: 29

pranay_18

New Member
Alumni
Hello!!!

I'm Pranay!!

i have a doubt regarding the Android app development course!!
At the time of the enrollment in course its mentioned that the app what you be learning, and even my online sessions were completed but till now no one taught about the flappy bird game app development !!!!

So can i know the reason for that!!!

Thanks and Regards,
S. Pranay.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hello ,
I have a doubt and help me with this!
Hello!!!

I'm Pranay!!

i have a doubt regarding the Android app development course!!
At the time of the enrollment in course its mentioned that the app what you be learning, and even my online sessions were completed but till now no one taught about the flappy bird game app development !!!!

So can i know the reason for that!!!

Thanks and Regards,
S. Pranay.
Hi Pranay,

I have already responded to your email ID.
 

Rakesh Deshpande

Moderator
Simplilearn Support
One of the Important Concept in Android App Development and every Android App Developer Must know is SQlite- Database Programming with Android.

Let's see how to go ahead with SQLite ( Beginners - this might be helpful for you ) :

SQlite - It is one of the Database Programming accompanied/incorporated in Android Studio by Developer Community. In order to store the data in tabular form, to enhance the data instantiation and to perform operations on the data sets like insertion, Deletion and much more - this is the nicest approach.

Abstract Classes used : SQLiteOpenHelper , Database statements , getReadabledatabases(); , getwritabledatabases(); , ContentValues , Cursor .

1. 2 Java files :

a) Mydatabase : to write all the operational statements of DB.

b) MainActivity : to link the UI to DB and to decide whether to write the data to DB or read the data from DB.

2. 1 Xml File : To input all the values like username, password, login button & Sign up button.

Here is the explanation for the same :
1. Extend the SQLiteOpenHelper with the newly created Base Class.
2. Design the UI i.e. SIgnup Button and EditTexts before you actually call the IDs of the Button & EditTexts in the backend.
3. Update the comments where ever required.
4. You have to use the Object Creation , Super() classes , SQL DB creation, with the statements.
5. Attached are the files to download and try.

Here is the thing, The code is error free but there is a bug which you have to clear it and update the answer here. Let's see the correct Answers on this.
 

Attachments

  • MainActivity.txt
    2.7 KB · Views: 11
  • Mydatabase.txt
    1.3 KB · Views: 10
  • XML.txt
    2.4 KB · Views: 10

Varun_112

Member
Alumni
Hi, I am about to upload the Calculator app project. When I click on the submit button, it asks me for a 'WriteUp'. What am I expected to upload there?
 

Neha Jain_1

Learning Consultant
Staff member
Simplilearn Support
Hi, I am about to upload the Calculator app project. When I click on the submit button, it asks me for a 'WriteUp'. What am I expected to upload there?
Hi Varun,

If you would like to share some details on your project you can write the same on a word doc and attach it.
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hello Everyone,

There is an important announcement, Since there is an issue with respect to the recordings of the session, We have escalated it to the concerned team and the team is already working on the resolution. We request your co operation for next 2 - 3 working days since all the links are re-synced and provide you error free links. You might not see the " Download Recordings " on your batch. Do not worry, it will be visible once the issue is resolved. Thank you in advance.

You can always chat or get on a call with us for an instant response. We're always around to help you achieve your career goals!
 

Shalini Mittal

Active Member
Trainer
Hello Sat-Sun Evg(7:30 - 11:30 pm ) batch,

PFA the codes till date.
 

Attachments

  • first app.zip
    204.6 KB · Views: 18
  • second app.zip
    43.1 KB · Views: 11
  • third app.zip
    57.5 KB · Views: 10

_3945

Member
Alumni
Hi Rakesh,

Can you also share the link with me? I have the same issue, cannot hear the lecture. Link of class3 (Batch started on jan 14). Thanks!

Vally
 

Varun_112

Member
Alumni
Hi,

I missed 28th January's class. I downloaded the recording today and noticed that there is no sound. Just bringing this to your notice. Thanks!
 

Avisha Jasubhai

Member
Alumni
Hi!! I downloaded the recording for the 28th January class and there is no sound on it. I also wanted to ask that where would the files of the codes from the classes be uploaded?
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hi!! I downloaded the recording for the 28th January class and there is no sound on it. I also wanted to ask that where would the files of the codes from the classes be uploaded?
Hello Avisha,

I have share the recordings to you as well. Please let us know if still the issue persists.
 

_3945

Member
Alumni
Hi Rakesh,

Can you also share the link with me? I have the same issue, cannot hear the lecture. Link of class3 (Batch started on jan 14). Thanks!

Vally

Hello Vally,

I shared the recordings. Please download with 24 hours.
Hi Rakesh,

Sorry, I missed downloading the links within 24 hours. Can you resend the links(very sry for the trouble). Also I have issue while Im working on weather app. Can you help resolve this?

I created API key in OpenWeatherApp website.
Appended it to the URL and it looks like
http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90
I could open this file in browser with zero issues.

Then I did:
con = (HttpURLConnection) ( new URL(url)).openConnection();
Log.i(" CON ", con.toString());
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();

con value is (in logs)
CON: com.android.okhttp.internal.huc.HttpURLConnectionImpl:http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Now, when i try to read this response, I get
java.io.FileNotFoundException: http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Whta could be the possible reasons behind this? Your help much appreciated. Thanks

Vally
 

Avisha Jasubhai

Member
Alumni
Hi!!
I downloaded the recording for the session on 29th January but there is still no audio. Can you please send me the link to download the recording?
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hi Rakesh,

Sorry, I missed downloading the links within 24 hours. Can you resend the links(very sry for the trouble). Also I have issue while Im working on weather app. Can you help resolve this?

I created API key in OpenWeatherApp website.
Appended it to the URL and it looks like
http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90
I could open this file in browser with zero issues.

Then I did:
con = (HttpURLConnection) ( new URL(url)).openConnection();
Log.i(" CON ", con.toString());
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();

con value is (in logs)
CON: com.android.okhttp.internal.huc.HttpURLConnectionImpl:http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Now, when i try to read this response, I get
java.io.FileNotFoundException: http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Whta could be the possible reasons behind this? Your help much appreciated. Thanks

Vally
Hello Vally,

Try Quoting the API Key as CON: com.android.okhttp.internal.huc.HttpURLConnectionImpl:"http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90" ;

It seems , you query has been accepted as a file name instead of URL. Check if you have called the URI Method.
 

Varun_112

Member
Alumni
Hi Rakesh,

Sorry, I missed downloading the links within 24 hours. Can you resend the links(very sry for the trouble). Also I have issue while Im working on weather app. Can you help resolve this?

I created API key in OpenWeatherApp website.
Appended it to the URL and it looks like
http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90
I could open this file in browser with zero issues.

Then I did:
con = (HttpURLConnection) ( new URL(url)).openConnection();
Log.i(" CON ", con.toString());
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();

con value is (in logs)
CON: com.android.okhttp.internal.huc.HttpURLConnectionImpl:http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Now, when i try to read this response, I get
java.io.FileNotFoundException: http://api.openweathermap.org/data/2.5/weather?q=London, UK&lang=en&APPID=f7f32eccf25adce88834c8bffa850f90

Whta could be the possible reasons behind this? Your help much appreciated. Thanks

Vally
Hi,

I'm also working on the Weather App and what you can do is split the URL and API Key.

This is what I used for testing and it works (as of now :p)

URL url = new URL(String.format(OPEN_WEATHER_MAP_URL, lat, lon));
HttpURLConnection connection =(HttpURLConnection)url.openConnection();

connection.addRequestProperty("x-api-key", OPEN_WEATHER_MAP_API);

Where OPEN_WEATHER_MAP_URL is
http://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&units=metric

Hope this helps
 

Rakesh Deshpande

Moderator
Simplilearn Support
Hi,

I'm also working on the Weather App and what you can do is split the URL and API Key.

This is what I used for testing and it works (as of now :p)

URL url = new URL(String.format(OPEN_WEATHER_MAP_URL, lat, lon));
HttpURLConnection connection =(HttpURLConnection)url.openConnection();

connection.addRequestProperty("x-api-key", OPEN_WEATHER_MAP_API);

Where OPEN_WEATHER_MAP_URL is
http://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&units=metric

Hope this helps
Appreciated Varun!
 

Varun_112

Member
Alumni
Hi,

Having some issues while getting location on device

I'm unable to retrieve the values of longitude and latitude in my code.

Please find my code below.
************************CODE************************************

public class MainActivity extends AppCompatActivity implements LocationListener {

private final static String TAG = MainActivity.class.getSimpleName();

TextView mLongitudeText;
TextView mLatitudeText;

LocationManager locationManager;
Location location;
double latitude;
double longitutde;

@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mLatitudeText = (TextView) findViewById(R.id.mLatitudeText);
mLongitudeText = (TextView) findViewById(R.id.mLongitudeText);

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
List<String> providers = locationManager.getAllProviders();
for (int i = 0; i < providers.size(); i++) {
Log.i(TAG, providers.get(i));
}
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling// ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details.Log.i(TAG, "Permission Granted");
return;
}
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
mLatitudeText.setText("Latitude: " + location.getLatitude());
mLongitudeText.setText("Longitude: " + location.getLongitude());
}
}

@Overrideprotected void onStart() {
super.onStart();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling// ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details.return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 1000, this);
}

@Overrideprotected void onStop() {
super.onStop();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling// ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details.return;
}
locationManager.removeUpdates(this);
}

@Overridepublic void onLocationChanged(Location location) {

}

@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {

}

@Overridepublic void onProviderEnabled(String provider) {

}

@Overridepublic void onProviderDisabled(String provider) {

}
}
 

Beena_3

Active Member
Simplilearn Support
Hi!! I downloaded the recording for the 4th Feb session but there is no sound. Can you please send the recording for 4th Feb?
Hello Avisha,

We are working on it and we shall respond accordingly with the links. We appreciate your co operation in advance.
 

Rakesh Deshpande

Moderator
Simplilearn Support
@Varun_112


Try This, Add toString() Method similar like this :
long......setText(DATATYPE.toString(longitude));
lat.....setText(DATATYPE.toString(latitude));

after :
if (location != null) {
mLatitudeText.setText("Latitude: " + location.getLatitude());
mLongitudeText.setText("Longitude: " + location.getLongitude());
 
Top