Help me modify with necessary changes needed to use the value/string(number) passed by user for phone-calling that string itself
Intent phnIntent = new Intent(Intent.ACTION_CALL);
phnIntent.setData(Uri.parse("tel:+91987654321"));
you can use like this :
String strTelNo = "+91987654321";
Intent intent = new Intent("android.intent.action.CALL");
Uri data = Uri.parse("tel:"+ strTelNo );
intent.setData(data);
startActivity(intent);
Try this link.
Make sure you add the necessary permission in the Android Manifest.
<uses-permission android:name="android.permission.CALL_PHONE" />
Just add the line startActivity(phnIntent);
EDIT:
Activity A
Intent someIntent = new Intent(A.this, B.class);
someIntent.putExtra("phoneNumber", number);
startAcitivty(someIntent);
Acitivity B
Bundle extras = getIntent().getExtras();
String number = extras.getInt("phoneNumber");
Use the number string to make the call.
Related
I want to open my phone dialer .But it shows error. I have declared permissions for CALL_PHONE on Android Manifest and also declared class in Android Manifest.
case R.id.action_call:
Log.d("Action_call","INside Action call");
Intent dialer = new Intent(Intent.ACTION_DIAL);
startActivity(dialer);
return true;
You don't need any permissions for ACTION_DIAL Intent. So remove CALL_PHONE permission from AndroidManifest.xml.
You have not pass any number to fire dial Intent.
Use tel: followed by the phone number as the value passed to Uri.parse():
Try this code.
String number = "1234567890";
Uri number = Uri.parse("tel:" + number);
Intent dial = new Intent(Intent.ACTION_DIAL);
dial.setData(number);
startActivity(dial);
EDIT:
You can first check whether telephony is supported on device
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
I hope it helps!
Use Uri to parse number..
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone)); //String phone
startActivity(call);
Use try/catch.
Use Uri to parse number.
Don't need any permissions for ACTION_DIAL intent.
try{
Intent call_intent = new Intent(Intent.ACTION_DIAL);
call_intent.setData(Uri.parse("tel:"+phone_number));
startActivity(call_intent);
}catch(Exception e){
}
I want to be able to allow my users to uninstall application from my application. Just like what Google Play Store allow to their users(Please below image)
the main question is that how can define a button that by pressing it we can uninstall an app by giving the package name or some other info.Just like the uninstall button on the image.
try
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:app package name"));
startActivity(intent);
If this doesn't work then
change intent to:
Intent.ACTION_UNINSTALL_PACKAGE);
and set datatype as:
intent.setDataAndType(Uri.parse("package:" + your app package name));
Try this:
Intent intent = null;
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
} else {
intent = new Intent(Intent.ACTION_DELETE);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.fromParts("package", packageName, null));
if(intent.resolveActivity(getActivity( ).getPackageManager()) != null) {
startActivity(intent);
}
kotlin
// This is for kotlin
< uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
Code
val intent = Intent(Intent.ACTION_DELETE)
intent.data = Uri.parse("package:"+app_package_name)
startActivity(intent)
// note app package name should be given properly.
Below shown is the code, i am using to get values from the intent
Bundle extras = intent.getExtras();
extras object has the follwoing information
Bundle[{message=Order #400000063 is Ready for pickup, android.support.content.wakelockid=2, collapse_key=do_not_collapse, from=552489062080, e_id=364}]
When I say
extras.getString("message");
returns null. I am not sure how to get the values ?
In your Activity1:
Intent i = new Intent(Activity1.this,Activity2.class);
i.putExtra("message", "string_value");
startActivity(i);
In your Activity2:
// do a try/catch block or check
//if getIntent().getStringExtra("message") is null
String str = getIntent().getStringExtra("string_tag");
Probably you are writing different tag name ..
Use the same tag name which you used while sending data with Intent.
while sending data if you used code as
Intent i = new Intent(Activity1.this,Activity2.class);
i.putExtra("TAG_NAME", "string_value");
startActivity(i);
then use code below as
String str = getIntent().getStringExtra("TAG_NAME");
try it...
SO,how do i do it? I have tried the following
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
context.startActivity(intent);
The above works only with mailto or tel, what about name?
you can also send Person Name using Intents.Insert.NAME with Intent as:
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
// add name here
intent.putExtra(Intents.Insert.NAME, sender_Name_here);
context.startActivity(intent);
I need to show/interact with a new contact before create it, and I need a simple way to add it to the phone contacts.
this is the code I use:
String contactPhone = "33333333";
Uri contactUri = Uri.parse(String.format("tel: %s", contactPhone));
Intent addContactIntent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "FirstName" );
addContactIntent.putExtra(ContactsContract.Intents.Insert.COMPANY,"CompanyName");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,contactPhone);
addContactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL,"contact#email.com");
startActivity(addContactIntent);
and this is the result. The problem is that the Intent show me only the Phone instead all the info added.
ContactsContract.Intents.Insert.ACTION if you want to interact before create it:
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION,ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.NAME, getName());
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, getCompany());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, getEmail());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, getPhone());
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, getAddress());
startActivity(intent);
This works pretty well. I hope this will help you.
This site (http://wiresareobsolete.com/2011/10/simplifying-interaction-with-contacts/) shows and gives examples) that SHOW_OR_CREATE_CONTACT can only trigger off "tel" or "mailto"/email for searches.