Android - Display FCM notification message in Listview onClicking Notification - android

I have successfully sent Firebase notifications using my own server to Android app and I am listing the messages in a ListView in a new activity by clicking the notification. My issue is if I click on one particular notification, all unread notification messages are getting displayed in ListView.
FirebaseMessageservice.java:
private void sendPushNotification(JSONObject json) {
//optionally we can display the json into log
Log.e(TAG, "Notification JSON " + json.toString());
try {
//getting the json data
JSONObject data = json.getJSONObject("data");
//parsing json data
String title = data.getString("title");
String message = data.getString("message");
String imageUrl = data.getString("image");
list.add(message);
Collections.reverse(list);
System.out.println(list);
MyNotificationManager mNotificationManager = new MyNotificationManager(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
//if there is no image
if(imageUrl.equals("null")){
//displaying small notification
mNotificationManager.showSmallNotification(title, message, intent);
}else{
//if there is an image
//displaying a big notification
mNotificationManager.showBigNotification(title, message, imageUrl, intent);
}
} catch (JSONException e) {
Log.e(TAG, "Json Exception: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
HomeActivity.java
public class HomeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ListView listView = (ListView) findViewById(R.id.notification_list);
adapter = new ListViewAdapter(this, list);
listView.setAdapter(adapter);
}
}
Output Screens
If i click on Hello Mom, It moves to next activity with listview but with both messages are getting displayed "1. Mom 2. Dad"

Related

Firebase notification not showing properly in android app when app is in background?

I am using the below code for showing a notification.
when I trigger a notification from the console. If the app is in the foreground. I am getting customize notification properly.
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
}
}
}
private void handleNotification(String message) {
sendNotification(message);
}
private void handleDataMessage(JSONObject json) {
try {
JSONObject data = json.getJSONObject("data");
String message = data.getString("message");
sendNotification(message);
} catch (JSONException ignored) {
} catch (Exception ignored) {
}
}
public void sendNotification(String message) {
NotiManager.createNotification(getApplicationContext());
}

Send FCM to user subscribed to a topic programmatically

I am creating a BloodBank app in which, when the user requests for the blood, It takes the requested Blood group and search the same in the database. It displays list of all the users who can donate to that blood group.
In the list, I have already implemented an option to message and call the user. Additionally, I want the App to send a notification to all users who have the same blood group.
For achieving this I have subscribed the user to a topic at successful login and sent him a notification but I have done this through the console.
What I want to achieve is, as a user requests the blood and while showing him the list of all users who can donate, App should also send a notification to all the users who have subscribed to that topic.
So is there any possible way I can programmatically send FCM to all the users subscribed to the same topic.
Here I'm subscribing user to a topic at successful Login:
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
progressDialog.dismiss();
topicSubscription();
} else {
progressDialog.dismiss();
String exception = task.getException().getMessage();
HelperClass.showSnakbarMsg(rootView, exception);
}
}
});
}
private void topicSubscription() {
FirebaseMessaging.getInstance().subscribeToTopic("Blood")
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
String msg = getString(R.string.msg_subscribed);
if (!task.isSuccessful()) {
msg = getString(R.string.msg_subscribe_failed);
} else {
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
Log.d("log", msg);
Toast.makeText(LoginActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
This is my Firebase messaging class:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* #param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
I have read about it and many have said to hit an API for this to send FCM programmatically. But I am creating the whole app in firebase so my DataBase is also in firebase and as my database is in firebase I can't use API for one notification only like I have to manage some table in DB for that notification and for only one table I have to manage a separate DB.
So is there any way that I can send FCM programmatically to all users who have subscribed to the same topic, on successful loading of the donor list which shows the user who can donate to the requested blood group.
Thanks
You can directly send push notification directly from android, to all the devices subscribed to the topic, check out the following link how to send msgs directly from android, but in this example user is sending message one to one, to send fcm message to user subscribed to a topic, you need to change the message format as specified by fcm documentation
User App
private void latLngNotification() {
Location loc1 = new Location("");
loc1.setLatitude(Double.parseDouble(userLat));
//loc1.setLongitude();
Location loc2 = new Location("");
loc2.setLatitude(Double.parseDouble(attendanceLat));
//loc2.setLongitude();
float distanceInMeters = loc1.distanceTo(loc2);
if (distanceInMeters > 50) {
//Toast.makeText(this, "distance: " + distanceInMeters, Toast.LENGTH_SHORT).show();
sendNotification();
} else {
//Toast.makeText(this, "distance: " + distanceInMeters, Toast.LENGTH_SHORT).show();
Toast.makeText(this, "You are in home...", Toast.LENGTH_SHORT).show();
}
}
private void sendNotification() {
String TOPIC = "/topics/admin_app"; //topic has to match what the receiver subscribed to
JSONObject notification = new JSONObject();
JSONObject notifcationBody = new JSONObject();
String title = "Quarantine outside";
String message = mobileno + " User is out of his area";
try {
notifcationBody.put("title", title);
notifcationBody.put("message", message);
notification.put("to", TOPIC);
notification.put("priority", "high");
notification.put("data", notifcationBody);
} catch (JSONException e) {
Log.e(TAG, "onCreate: " + e.getMessage());
}
Notification(notification);
}
private void Notification(JSONObject notification) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest("https://fcm.googleapis.com/fcm/send", notification,
response -> Log.i(TAG, "onResponse: " + response.toString()),
error -> {
Toast.makeText(GetLocationActivity.this, "Request error", Toast.LENGTH_LONG).show();
Log.i(TAG, "onErrorResponse: Didn't work");
}) {
#Override
public Map<String, String> getHeaders() {
Map<String, String> params = new HashMap<>();
params.put("Authorization", "key=AAAAwxBqu5A:APA91bERpf-1rh02jLciILt1rsLv7HRrFVulMTEAJXJ5l_JGrSHf96qXvLQV0bIROob9e3xLK4VN8tWo-zBPUL39HjxyW4MsX5nKW_NiQlZGgLDCySVwHXADlg16mpLUjgASj--bk-_W");
params.put("Content-Type", "application/json");
return params;
}
};
MySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectRequest);
}
Admin App
FirebaseMessaging.getInstance().subscribeToTopic("admin_app");
Intent intent = getIntent();
if (intent != null) {
String userPhone = intent.getStringExtra("message");
//Toast.makeText(this, userPhone, Toast.LENGTH_SHORT).show();
message_txt.setVisibility(View.VISIBLE);
message_txt.setText(userPhone);
} else {
message_txt.setVisibility(View.GONE);
//Toast.makeText(this, "no data", Toast.LENGTH_SHORT).show();
}

Getting error in Firebase one to one chat app Notifications

I have made a one to one chat app and I have implemented chat notifications but when I am sending notifications from the user app to the doctor app but my doctor app crashes as soon as I am clicking on the chat notification
This is my Java class where I am handling the notification if my app is in foreground so this class will handle notifications so now in this class I am calling firebase database and taking some data from there and passing that data as an extra data with the resulting intent but when that resulting intent directs the app to the particular chat view that database data is not there
This is the Log of my app
E/MyFirebaseMessaging: From:408315985482
07-05 16:19:33.803 4399-6278/com.tech.pritz.bemoprovider D/MyFirebaseMessaging: in between Firebase and auth
07-05 16:19:33.805 4399-6278/com.tech.pritz.bemoprovider D/MyFirebaseMessaging: Message data payload: {idRe, username=komal , message=hi}
07-05 16:19:33.805 4399-6278/com.tech.pritz.bemoprovider D/MyFirebaseMessaging: app in background
07-05 16:19:33.813 4399-6278/com.tech.pritz.bemoprovider E/MyFirebaseMessaging: image not found
07-05 16:19:33.825 4399-6278/com.tech.pritz.bemoprovider D/NotificationUtil: New Message
D/MyFirebaseMessaging: Entered into the database
07-05 16:19:34.359 4399-4399/com.tech.pritz.bemoprovider D/MyFirebaseMessaging: HKNi1sezUpbwJSeEGos44FtfUw43
You can see here it is showing entered in the database also and it is getting that data also but when I pass it as an intent it is not found in another activity.
Crash log
Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'java.lang.String
com.tech.pritz.bemoprovider.model.Provider.getId()' on a null object
reference at
com.tech.pritz.bemoprovider.bemo.ChatView.ini(ChatView.java:‌​350) at
com.tech.pritz.bemoprovider.bemo.ChatView.onCreate(ChatView.‌​java:150)
public class MyFirebaseMessaging extends FirebaseMessagingService
{
private static final String TAG=MyFirebaseMessaging.class.getSimpleName();
private NotificationUtil notificationUtil;
private DatabaseReference pathFirebase;
private FirebaseAuth auth;
private Provider mprovider;
#Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
Log.e(TAG,"From:"+ remoteMessage.getFrom());
pathFirebase = FirebaseDatabase.getInstance().getReference();
Log.d(TAG,"in between Firebase and auth");
auth = FirebaseAuth.getInstance();
if(remoteMessage ==null )
{
return;
}
//check if message contains a notification payload
if(remoteMessage.getNotification()!=null)
{
String tittle = remoteMessage.getNotification().getTitle();
Log.e(TAG,"Notification Body:" + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification().getBody(),tittle,null, mprovider);
}
//checks to see if message contains a data payload
if(remoteMessage.getData().size() > 0)
{
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
String imageUrl = remoteMessage.getData().get("image");
// String message = remoteMessage.getData().get("message");
// String title = remoteMessage.getData().get("title");
// String name = remoteMessage.getData().get("username");
String message= remoteMessage.getData().get("message");
String name= remoteMessage.getData().get("username");
String title= "New Message";
String iduser= remoteMessage.getData().get("iduser");
String email= remoteMessage.getData().get("email");
String gcm_id= remoteMessage.getData().get("idGCM");
String conversation_id=remoteMessage.getData().get("conversation_id");
Log.d(TAG,"app in background");
pathFirebase.child("users").child(auth.getCurrentUser().getUid())
.addValueEventListener(
new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Log.d(TAG,"Entered into the database");
mprovider = dataSnapshot.getValue(Provider.class);
UserDataHolder.getInstance().setmName(mprovider.getName());
// Intent intent = new Intent(MyFirebaseMessaging.this, ListPatients.class);
mprovider.setId(auth.getCurrentUser().getUid());
UserDataHolder.getInstance().setmUserId(mprovider.getId());
// intent.putExtra("user", provider);
//startActivity(intent);
//finish();
Log.d(TAG,mprovider.getId());
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MyFirebaseMessaging.this, "Failed", Toast.LENGTH_SHORT).show();
}
});
// Log.d(TAG,mprovider.getId());
// app is in background, show the notification in notification tray
Intent resultIntent = new Intent(getApplicationContext(),ChatView.class);
resultIntent.putExtra("user_id", iduser);
resultIntent.putExtra("email", email);
resultIntent.putExtra("User_display_name",name);
resultIntent.putExtra("user_gcm_id",gcm_id);
resultIntent.putExtra("conversation_id",conversation_id);
// resultIntent.putExtra("providerLocal",mprovider);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// resultIntent.putExtra("message", message);
// check for image attachment
if (TextUtils.isEmpty(imageUrl))
{
Log.e(TAG,"image not found");
showNotificationMessage(getApplicationContext(), title, message,name,resultIntent,mprovider);
}
else
{
// image is present, show notification with image
Log.e(TAG,"image found");
showNotificationMessageWithBigImage(getApplicationContext(), title, message, resultIntent, imageUrl);
}
}
}
private void handleNotification(String message,String title,String name,Provider provider)
{
if(!NotificationUtil.isAppInBackground(getApplicationContext()))
{
Intent resultIntent = new Intent(getApplicationContext(), ChatView.class);
showNotificationMessage(getApplicationContext(), title, message,null,resultIntent, provider);
}
else
{
Intent resultIntent = new Intent(getApplicationContext(), ChatView.class);
showNotificationMessage(getApplicationContext(), title, message,null,resultIntent, mprovider);
}
}
private void showNotificationMessageWithBigImage(Context applicationContext, String title, String message, Intent resultIntent, String imageUrl)
{
notificationUtil = new NotificationUtil(applicationContext);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtil.showNotificationMessage(title, message,null,resultIntent,imageUrl);
}
private void showNotificationMessage(Context applicationContext, String title, String message,String name, Intent resultIntent,Provider mprovider)
{
// Log.d(TAG,mprovider.getId());
notificationUtil = new NotificationUtil(applicationContext);
resultIntent.putExtra("providerLocal",mprovider);
// resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtil.showNotificationMessage(title, message,name,resultIntent);
}
}
the problem is in this line :
UserDataHolder.getInstance().setmUserId(mprovider.getId());
the mprovider object is null

Android Volley URL with parameters

I have written a code using a volley library (GET) and I have to fetch the data from the rest API in Django.
Actually the problem is i am getting a user id while i login , i just saved that id through shared preferences and i have to pass the id in the URL to get wallet details but i am getting error
BasicNetwork.performRequest: Unexpected response code 403
public class Wallet extends AppCompatActivity {
TextView all_tv1;
Button credit_bt, debit_bt;
SharedPreferences pref;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.activity_wallet);
pref=getApplication().getSharedPreferences("Options", MODE_PRIVATE);
Integer Key_UserID=pref.getInt("UserId_Value", 0);
// String a = Key_UserID.toString();
/Json Request/
String uri = "http://staging.exol.in/wallet/wallet/api/wallet-detail/+Key_UserID";
RequestQueue requestQueue = Volley.newRequestQueue(this);
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, uri, null,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Toast.makeText(getApplicationContext(),"stop",LENGTH_SHORT).show();
// String data = "";
try {
for(int i=0; i< response.length(); i++) {
JSONObject obj = response.getJSONObject(i);
String tnx_id = obj.getString("tnx_id");
String transition_type = obj.getString("transition_type");
// String email = obj.getString("email");
// System.out.print("\nggtrgtg"+user+"\ngfg"+amount);
Toast.makeText(getApplicationContext(),tnx_id + transition_type ,LENGTH_SHORT).show();
// data = "" + id + "" + name + "" + email + "";
//txtDisplay.setText(txtDisplay.getText()+"\n" + id + "" + name + "\n" + email + "");
// Adds the data string to the TextView "results"
}
}
// Try and catch are included to handle any errors due to JSON
catch (JSONException e) {
// If an error occurs, this prints the error to the log
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),"Faled Misreably" ,LENGTH_SHORT).show();
}
});
//add request to queue
requestQueue.add(jsonArrayRequest);
setTitle("Wallet Window");
Toolbar toolbar1 = (Toolbar)findViewById(R.id.tool_bar);
setSupportActionBar(toolbar1);
all_tv1 = (TextView)findViewById(R.id.all_tv);
all_tv1.setMovementMethod(new ScrollingMovementMethod());
credit_bt = (Button)findViewById(R.id.credit_details1__bt);
debit_bt = (Button) findViewById(R.id.debit_details1__bt);
credit_bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Credit Tab", LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), Wallet_Credit.class);
startActivity(i);
finish();
}
});
debit_bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Debit Tab", LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), Wallet_Debit.class);
startActivity(i);
finish();
}
});
}
}
Your uri string is not set properly (notice the closing "). Instead of
String uri = "http://staging.exol.in/wallet/wallet/api/wallet-detail/+Key_UserID";
It should be
String uri = "http://staging.exol.in/wallet/wallet/api/wallet-detail/"+Key_UserID;

Intent not receive data in second Activity in volley

Hey developers i am tried send the data through intent
i am sending data A activity to B activity data is send A Activity properly but B Activity is not receive but some data is receive but some data not receive
Code is A Activity
private void requestForSMS(final String mobile) {
StringRequest strReq = new StringRequest(Request.Method.POST,
config.Config.URL_REQUEST_SMS, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
final String user = responseObj.getString("uid");
String message = responseObj.getString("msg");
Intent intent1 = new Intent(getApplicationContext(),HttpService.class);
intent1.putExtra("uid", user); // <---Sending data here this data not recive B Activity ------>
Log.d("user id going","====>"+user);
if(!user.equalsIgnoreCase("")){
pref.setIsWaitingForSms(true);
viewPager.setCurrentItem(1);
txtEditMobile.setText(pref.getMobileNumber());
layoutEditMobile.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"ErrorToast: " + message,
Toast.LENGTH_LONG).show();
}
// hiding the progress bar
progressBar.setVisibility(View.GONE);
} catch (JSONException e) {
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "ErrorResponce: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("key","xxxxxxxxxxxxx");
params.put("mobile", mobile);
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
strReq.setRetryPolicy(policy);
// Adding request to request queue
newapp.getInstance().addToRequestQueue(strReq);
}
private void verifyOtp() {
String otp = inputOtp.getText().toString().trim();
if (!otp.isEmpty()) {
Intent grapprIntent = new Intent(getApplicationContext(), HttpService.class);
// <---- sending data here also B Activity---->
grapprIntent.putExtra("key","xxxxxxxxxxxx");
grapprIntent.putExtra("mobileverify", otp);
startService(grapprIntent);
} else {
Toast.makeText(getApplicationContext(), "Please enter the OTP", Toast.LENGTH_SHORT).show();
}
}
private static boolean isValidPhoneNumber(String mobile) {
String regEx = "^[0-9]{10}$";
return mobile.matches(regEx);
}
B Activity
public class HttpService extends IntentService {
private static String TAG = HttpService.class.getSimpleName();
public HttpService() {
super(HttpService.class.getSimpleName());
}
#Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
String otp = intent.getStringExtra("mobileverify");
final String user1 = intent.getStringExtra("uid"); //<---- this is not recive value ---->
verifyOtp(otp,user1);
}
}
/**
* Posting the OTP to server and activating the user
*
* #param otp otp received in the SMS
*/
private void verifyOtp(final String otp, final String user1){
StringRequest strReq = new StringRequest(Request.Method.POST,
config.Config.URL_VERIFY_OTP, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
// Parsing json object response
// response will be a json object
String message = responseObj.getString("msg");
if (message!="") {
// parsing the user profile information
JSONObject profileObj = responseObj.getJSONObject(response);
String mobile = profileObj.getString("mobile");
PrefManager pref = new PrefManager(getApplicationContext());
pref.createLogin(mobile);
Intent intent = new Intent(HttpService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Toast.makeText(getApplicationContext(), "HTTPIF"+message, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "HTTPELSE"+message, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "HTTPError: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("key","xxxxxxxxxx");
params.put("mobileverify", otp);
params.put("uid",user1); // here its given error
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
MyApplication.getInstance().addToRequestQueue(strReq);
}
Please Help me Thanks
Your grapprIntentdoesn't contain a value for "uid" key because you don't put it. You use some intent1 which is not used anywhere more. Instead you need to put "uid" into grapprIntent:
grapprIntent.putExtra("uid", user);
Maybe grapprIntent should be global variable for the class or find a way to pass it between methods.
Create A Global variable in your Application class and Use set and get Methods
like this
Application.class
private String user;
public String setuser(String usermy) {
this.user = usermy;
return null;
}
public String getuser()
{
return user;
}
where you want to send value set value like as your code
SMSActivity
MyApplication myUser = (MyApplication)getApplicationContext();
#Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
String user = responseObj.getString("uid");
String user1 = myUser.setuser(user);
And Get Value in your HttpService.class
Like this
MyApplication uidinfo = (MyApplication)getApplicationContext();
final String user = uidinfo.getuser();
and mention manifest.xml inside Application tag
<application
android:name=".MyApplication"
/>
happy coding

Categories

Resources