5,595,268 Members 46,908 Now Online
XDA Developers Android and Mobile Development Forum

[Q] How do I display text from a messgae into a toast?

Tip us?
 
shawnleeyh
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: Dec 2013
Default [Q] How do I display text from a messgae into a toast?

Hi all skilled developers,

I am a newbie in coding, and I just want to make some small changes to my app.

It is a licensing feature.

1) Licensee information are stored at a very simple website. With columns for Names, IMEI and Remarks.
2) I have the following chunk of code:
Code:
if(hadLicense) {
				new AlertDialog.Builder(InsuranceGuruSplash.this)
				.setTitle("License")
				.setMessage("Your device is registered.\nWelcome.")
				.setPositiveButton("Send", new DialogInterface.OnClickListener() 
				Intent intent = new Intent(InsuranceGuruSplash.this, MainActivity.class);
				startActivity(intent);
				
				
				finish();
I want to show a toast saying,
Quote:
Welcome, Shawn. Your device is registered till DD/MM/YY.
Can someone teach me how I can go about doing this?
 
SimplicityApks
Old
#2  
SimplicityApks's Avatar
Senior Member
Thanks Meter 277
Posts: 252
Join Date: May 2013
Location: Aachen
You can show a toast using:
Code:
 
Toast.makeText(context, text, duration).show();
Just make the text String first with the text and time. For duration use Toast.LENGTH_SHORT
 
shawnleeyh
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: Dec 2013
SimplicityApks,

Thanks for your reply. I still don't really know what you mean. how do I echo a text from a website into the app's toast?

This is the full code:
Code:
		protected Void doInBackground(Void... params) {
			String url_for_sale = "www(dot)heyfellas(dot)com/guru/index.php";
			parseLicense(url_for_sale);

			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
			final String imei = mngr.getDeviceId();
			
			boolean hadLicense = false;
			for(LicenseInfo license: licenses) {
				if(license.phoneIMEI.equals(imei))
					hadLicense = true;
			}
			
			if(hadLicense) {
				Intent intent = new Intent(InsuranceGuruSplash.this, MainActivity.class);
				startActivity(intent);
				
				finish();
			} else {
				new AlertDialog.Builder(InsuranceGuruSplash.this)
				.setTitle("License")
				.setMessage("Your device is not registered.\nPlease send your details to the admin.")
				.setPositiveButton("Send", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						finish();
						
						Intent i = new Intent(Intent.ACTION_SEND);
						i.setType("message/rfc822");
						i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"admin@gmail.com"});
						i.putExtra(Intent.EXTRA_SUBJECT, "Request for license");
						i.putExtra(Intent.EXTRA_TEXT   , "UserName: \n\nPhone Number: \n\nEmail: \n\nIMEI: " + imei);
						try {
						    startActivity(Intent.createChooser(i, "Send mail..."));
						} catch (android.content.ActivityNotFoundException ex) {
						    Toast.makeText(PropertyGuruSplash.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
						}
					}
				})
				.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						finish();
					}
				})
				.create().show();
			}
		}
	}
 
EmptinessFiller
Old
#4  
Member
Thanks Meter 21
Posts: 88
Join Date: Sep 2013
You need
[java]
String name = ...;
String date = ....;
Toast.makeToast(Activity.this, name + ", you have registered since "+date, Toast.LENGTH_SHORT).show();[/java]
 
vijai2011
Old
#5  
Recognized Developer
Thanks Meter 459
Posts: 940
Join Date: Oct 2011
Location: chennai

 
DONATE TO ME
I suppose, you are strong at server side than in client programming? Then echo the result in your desired format in your php and read it in java then display it in toast. Use the below snippet:
Code:
HttpClient httpclient=new DefaultHttpClient(); 
HttpPost httppost=new HttpPost("http://www(dot)heyfellas(dot)com/guru/index.php");
HttpResponse response = httpclient.execute(httppost);
String Result =  EntityUtils.toString(response.getEntity());
Toast.makeText(Context, Result, Toast.LENGTH_SHORT).show();
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes