I have an android app that should be able to open a chat in the telegram app by pressing a button.
I want to open an existing robot chat page DIRECTLY from my app. I have a valid token for my robot. How can this be achieved?
Thanks in advance.
robot name : #InfotechAvl_bot
robot token: 179284***********
//-------------
case ContentFragment.lMenuTelegram:
Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("org.telegram.messenger");
startActivity(LaunchIntent);
break;
To solve this problem you have to open robot id with this :
Intent telegram = new Intent(Intent.ACTION_VIEW , Uri.parse("https://telegram.me/InfotechAvl_bot"));
startActivity(telegram);
for Instagram and Telegram and WhatsApp you can use this methods
void getTelegram(){
try {
Intent telegramIntent = new Intent(Intent.ACTION_VIEW);
telegramIntent.setData(Uri.parse("https://telegram.me/diako099"));
startActivity(telegramIntent);
} catch (Exception e) {
// show error message
}
}
void getInstagram(){
try {
Intent instagramIntent = new Intent(Intent.ACTION_VIEW);
instagramIntent.setData(Uri.parse("https://www.instagram.com/diako_hasani99/"));
startActivity(instagramIntent);
} catch (Exception e) {
// show error message
}
}
void getWhatsApp(){
try{
String trimToNumner = "+989180074693"; //10 digit number
Intent intent = new Intent ( Intent.ACTION_VIEW );
intent.setData ( Uri.parse ( "https://wa.me/" + trimToNumner + "/?text=" + "" ) );
startActivity ( intent );
}catch (Exception e){
}
}
Related
currently i am using this but(to open map location on image click but some device having GoogleMap cant open the intent) the issue is even device has apps to handle the map intent it wont execute that part
any better way to do this?
like option to select from available apps and no apps to handle that then go for browser
private void openMap()
{
String Packagename ="com.google.android.apps.maps";
if (appInstalledOrNot(Packagename))
{
Uri uri = Uri.parse("geo:0,0?q=V.V.P.+Engineering+College+Kalavad+Road+Virda+Vajadi,+Rajkot");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
}else
{
try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://goo.gl/maps/ETVvFWw453CoeBHs9"));
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
Toast.makeText(getContext(), "Map application not found", Toast.LENGTH_SHORT).show();
}
}
I'm trying to make a button that launches one of two calculators should any of them exist on the device. I'm attempting to use the Android original calculator and Samsung. I'm trying to use the try-catch block method but it doesn't work. it can successfully launch the android calc but it doesn't successfully launch the Samsung one although I know for certain that the popup calc is on the device in question. instead, it goes to the catch with the Toast message. I'm assuming that I just don't have the right exception for the catch. please help me to find the correct code.
try {
//this is android original calculator
Intent i = new Intent();
i.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(i);
}
catch (UnsupportedOperationException e){
//This Launch Samsung calculator
Intent i = new Intent();
i.setClassName("com.sec.android.app.popupcalculator","com.sec.android.app.popupcalculator.Calculator");
startActivity(i);
} catch (Exception e) {
//should no calculator found it will display this massage
Toast tt = Toast.makeText(MainActivity.this,"SORRY I CANT OPEN CALCULATOR", Toast.LENGTH_LONG);
tt.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
tt.show();
}
break;
With #SonTroung help, I find the solution. I used his suggestion above but when using it, it crashed the app on the device which has no calculator. instead, I added another 'try {' nested in the first catch. that worked.
try {
//this is android original calculator
Intent i = new Intent();
i.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(i);
} catch (ActivityNotFoundException e) {
//This Launch Samsung calculator
try {
Intent i = new Intent();
i.setClassName("com.sec.android.app.popupcalculator", "com.sec.android.app.popupcalculator.Calculator");
startActivity(i);
} catch (Exception e) {
//should no calculator found it will display this massage
Toast tt = Toast.makeText(MainActivity.this, "SORRY I CANT OPEN CALCULATOR", Toast.LENGTH_LONG);
tt.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
tt.show();
}
}
I have implemented Razor Pay payment gateway in my Android application. Everything is working fine for debit/credit card.
I am facing problem with UPI payment. Actually for UPI payment user has to visit UPI app to make the payment. Everything is working for UPI as well but the only problem is callback methods are not invoked if payment is successful or not until and unless I visit the app again.
This is big problem for me because sometime if user pay via UPI app and does not open the app again, it's been difficult for me to save the entries in the database for the payment.
I am saving entries in the database every time success callback method is invoked. How do I call success method when app is in background but not closed.
Here is the code snippet:
To open the payment activity:
Intent intent = new Intent(context, PaymentActivity.class);
intent.putExtra("orderId", order_id);
intent.putExtra("totalAmount", String.valueOf(totalPrice));
intent.putExtra("email", email);
intent.putExtra("phoneNo", phone_number);
intent.putExtra("userId", user_id);
startActivityForResult(intent, 2);
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
To call the Razor pay Activity:
final Activity activity = this;
price = Double.parseDouble(total_price);
double paisa_double = price * 100;
int paisa_int = (int) paisa_double;
final Checkout checkout = new Checkout();
checkout.setKeyID(getResources().getString(R.string.razor_pay_key));
try {
JSONObject options = new JSONObject();
options.put("name", "Razorpay Corp");
options.put("description", "Order No: " + order_id);
options.put("order_id", razor_id);
//You can omit the image option to fetch the image from dashboard
options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png");
options.put("currency", "INR");
options.put("amount", String.valueOf(paisa_int));
//options.put("amount", "100");
JSONObject preFill = new JSONObject();
preFill.put("email", email);
preFill.put("contact", phone_no);
options.put("prefill", preFill);
JSONObject notes = new JSONObject();
notes.put("notes", order_id);
options.put("notes", notes);
checkout.open(activity, options);
} catch (Exception e) {
Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT)
.show();
e.printStackTrace();
}
And these are the callback methods:
#Override
public void onPaymentSuccess(String razorpayPaymentID, PaymentData paymentData) {
try {
//Toast.makeText(this, "Payment Successful: " + razorpayPaymentID, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("razorpayPaymentID", razorpayPaymentID);
setResult(2, intent);
finish();
} catch (Exception e) {
Log.e(TAG, "Exception in onPaymentSuccess", e);
}
}
#Override
public void onPaymentError(int code, String response, PaymentData paymentData) {
try {
Toast.makeText(this, "Payment failed: " + code + " " + response, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e(TAG, "Exception in onPaymentError", e);
}
}
Use Razor pay web hooks in the back end code for the above problem.
Link:
https://razorpay.com/docs/webhooks/
I want to send code *777# to dialer in android using intent but i have a problem only *777 key code will be displayed on dialer not # how to resolve this issue i'm new in android developer so please help me out this problem.
String dialler_Code = "*777#";
Toast.makeText(this, "clicked", Toast.LENGTH_LONG)
.show();
// Use format with "tel:" and phoneNumber created is stored in u.
Uri u = Uri.parse("tel:" + dialler_Code);
// Create the intent and set the data for the intent as the phone number.
Intent i = new Intent(Intent.ACTION_DIAL, u);
try {
// Launch the Phone app's dialer with a phone number to dial a call.
startActivity(i);
} catch (SecurityException s) {
// show() method display the toast with exception message.
Toast.makeText(this, s.getMessage() , Toast.LENGTH_LONG)
.show();
}
Try with String dialler_Code = Uri.encode("*777#");
**Use this : **
String enCodedHash = Uri.encode("#");
String number = "*151*1" + enCodedHash;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ number));
startActivity(callIntent);
I am using Default Google Maps in my android application. For that I used below code.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=sourcelat,sourcelang&daddr= destlat,destlang"));
// startActivity(intent);
try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
try {
Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=sourcelat,sourcelang&daddr= destlat,destlang"));
startActivity(unrestrictedIntent);
} catch (ActivityNotFoundException innerEx) {
Toast.makeText(ProductDescription.this, "Please install a maps application", Toast.LENGTH_LONG).show();
}
}
I am able to move to the Default Google Maps, But when I press Back Button My Android app was also getting Quit. How can I move to my application when back Button pressed in Maps Application ?
Please Someone Help me .