I am working on conference manager application .I am using ACTION_CALL function for making the call and ACTION_DIAL for dialing number.But the call is going separate and the dial action is separate.Can anyone help me?here is my code
private void call(int profileid) {
ProfileDo profile = adapter.getProfile(profileid);
int stepCount = 0;
long previousStepDelay = 0;
for (StepDO step : profile.getSteps()) {
Intent callIntent;
String url = "tel:" + step.getValue();
stepCount++;
if (stepCount == 1) {
callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
startActivity(callIntent);
} else {
try {
Thread.sleep(previousStepDelay * 1000);
System.out.println("hai");
} catch (InterruptedException e) {
e.printStackTrace();
}
callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(callIntent);
}
previousStepDelay = step.getDelay();
}
}
}
Related
I am using EasyPermission to taking permissions from user.
#AfterPermissionGranted(PERMISSIONS_REQUEST_READ_SMS)
private void readSMS() {
String[] perms = {Manifest.permission.READ_SMS};
if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_SMS)) {
initSMS();
} else {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.send_sms_rationale),
PERMISSIONS_REQUEST_READ_SMS, Manifest.permission.READ_SMS);
}
}
In my initSMS() I had tried to read messages from Android devices. Its worked fine for all devices except Xiaomi devices. I used TelephonyProvider class to read messages.
private void initSMS() {
TelephonyProvider provider = new TelephonyProvider(this);
List<Sms> sms = provider.getSms(TelephonyProvider.Filter.INBOX).getList();
for(int i = 0; i <= sms.size() - 1; i++) {
Log.d("Address",sms.get(i).address);
Log.d("Sms",sms.get(i).body);
Log.d("ReceivedDate",""+sms.get(i).receivedDate));
Log.d("State",""+sms.get(i).status);
Log.d("person",""+sms.get(i).person);
}
}
Is their any way to read all messages from Xiaomi devices?
I hope this will work for you. firstly you have to call function isMIUI() for checking miui mobile and then call this above function. this function will redirect to setting for taking service sms permission.
private void onDisplayPopupPermission() {
try {
// MIUI 8
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
localIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(localIntent);
} catch (Exception e) {
try {
// MIUI 5/6/7
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
localIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(localIntent);
} catch (Exception e1) {
// Otherwise jump to application details
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
}
}
I want to write a android application which can send sb a missed call. It means that application call to sb by about 5 second.
I know that this code start calling.
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
}
But I dont know how to stop it(after 5 second)?
Ps.This question have got mark -1 because question is stupid or my english is bad?
There is no direct way to do this because once you start the callIntent, the control will go to the calling application.
But there are workarounds to do this by getting the ITelephony object of TelephonyManagerusing java reflection.
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
}catch(Exception e){}
telephonyService.endCall();
source:
call-control-in-android
The simplest way is to use a delay Handler and make a new call to self after you have made the call to your target number. Hoping this is not for spam purposes which is frowned upon. In your code snipplet or loop you can have the below
if (checkPermission(Manifest.permission.CALL_PHONE)) {//targetMSISDN the phone no you are calling out to
String dial = "tel:" + targetMSISDN;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//delay a drop call
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//Do something after 10000ms
Toast.makeText(YourNotSpamActivity.this, "Calling me to end you!", Toast.LENGTH_SHORT).show();
//end call now
String TAG="ERR:";
try {
Log.v(TAG, "Get getTeleService...");
if (checkPermission(Manifest.permission.CALL_PHONE)) {
String dial = "tel:YourPhoneNumber";
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));//call yourself to terminate the first call
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: couldn't call ");
Log.e(TAG, "Exception object: " + e);
}
}
}, 10000);
//end the end call
} else {
Toast.makeText(YourNotSpamActivity.this, "Permission Call Phone denied", Toast.LENGTH_SHORT).show();
}
I'm facing with an intermittent application flow issue.
Here, I've got a Login screen where I'm able to login for the first time. But when I'm logging out and/or re-loging in, I'm unable to traverse further. As a work around, I need to uninstall my application and reinstall it and the flow is ok.
Can anyone please guide me on the possible issue.
LoginActivity.java
GetWebServiceManager passwordExpiryWSManager = new GetWebServiceManager();
//to check network connectivity (data connection/Wi-Fi)
ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInformation = connectionManager.getActiveNetworkInfo();
if (networkInformation != null && networkInformation.isConnected() == true) {
try {
// passwordExpiryString = passwordExpiryWSManager.execute("http://172.25.164.143:8088/api/Login/GetExpiredPassword/?lContactKey=" + username.getText().toString()).get();
passwordExpiryString = passwordExpiryWSManager.execute(AppConstants.URL + "/Login/GetExpiredPassword/?lContactKey=" + username.getText().toString()).get();
jsonObjectPassExpiry = new JSONObject(passwordExpiryString);
jsonArrayPassExpiry = jsonObjectPassExpiry.getJSONArray("LstLoginDetail");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
* Converting JSON string response from Webservice into Java Object
* */
if (jsonArrayPassExpiry != null) {
Gson gson = new Gson();
LoginTO[] loginExpTO = gson.fromJson(jsonArrayPassExpiry.toString(), LoginTO[].class);
loginListPassExpiry = Arrays.asList(loginExpTO);
intent = getIntent();
if (loginListPassExpiry.get(0).getlSuccess() == 1) {
intent.setClass(getApplicationContext(), PortfolioSummaryFragmentActivity.class);
// intent.putExtra("sToken", loginList.get(0).getsToken());
startActivity(intent);
} else {
intent.setClass(getApplicationContext(), PasswordExpiryActivity.class);
// intent.putExtra("sToken", loginList.get(0).getsToken());
startActivity(intent);
}
} else {
Toast.makeText(getApplicationContext(), "Service is not responding. Please try again later!!", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), "Network connection unavailable. Please check your data plan or Wi-Fi connection!!", Toast.LENGTH_SHORT).show();
}
Logout.java
public class LogoutActivity extends Activity {
private TextView successResponse;
private Intent intent;
private Button btnLLogin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logout_success);
successResponse = (TextView) findViewById(R.id.txtvwLSuccessMessage);
btnLLogin = (Button) findViewById(R.id.btnLLogin);
intent = getIntent();
successResponse.setText(intent.getStringExtra("successResponse"));
}
public void Login(View v) {
btnLLogin.setTextColor(getResources().getColor(R.color.black));
intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
#Override
public void onBackPressed() {
finish();
}
}
please use intent = new Intent(LogoutActivity.this, LoginActivity.class); instead of intent = new Intent(this, LoginActivity.class);
beside this use
most important
Add android:launchMode="singleTask " to the activity element in your manifest for Activity LoginActivity
How do I make a phone call when I get number from edittext? I try this but it does not work. I have a problem with passing variable number to Uri.parse() must be inside void the gettext?
public String string;
public String number;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText txtcallnumber;
txtcallnumber = (EditText)findViewById(R.id.callnumber);
string = txtcallnumber.getText().toString().trim();//There no work call
number = "tel:" + string;
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
call();
}
});
}
public void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
//callIntent.setData(Uri.parse("tel:xxxxxxx")); //This work
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;//There work call
callIntent.setData(Uri.parse(number));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("helloandroid dialing example", "Call failed");
}
You need to add Permission inside in your manifest file ::
<uses-permission android:name="android.permission.CALL_PHONE">
Inside your call() method try to use these Intent::
number=edittext.getText().trim();
no="tel:"+number;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(no)));
in onCreate method there is no need for :
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;
because onCreate is pretty much used for setting up the display and there will be no input by the user before the screen is set up but in onCall method after entering the text and pressing the button then it wouldd...you know.
Plus you should have this to check for nothing entered:
if(string!=null){
try{try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(number)));
} catch (ActivityNotFoundException activityException) {
Log.e("helloandroid dialing example", "Call failed");
}}else{
Log.d("helloandroid dialing example","nothing entered");}
I want to block a specific phone number that is in my database
I do a comparison between the number the user dialed, and the number in memory. If they are equal, I block the call.
My code:
public void onReceive(Context context, Intent intent) {
PlaceDataSQL placeDataSQL =new PlaceDataSQL(context);
ArrayList<String> getUsersPhoneNumbers= placeDataSQL.getUsersPhoneNumbers();
//TODO
//===========
//here I need to check the number
Bundle b = intent.getExtras();
String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
//String outGoingNumber = b.getString(TelephonyManager.);
Boolean find=false;
try {
for(int i=0;i<getUsersPhoneNumbers.size();i++)
{
if(incommingNumber.equals(getUsersPhoneNumbers.get(i)))
{
find=true;
break;
}
}
} catch (Exception e) {
incommingNumber="";
}
// ========================================
//here the problem
//=========================================
String phonenumber=b.getString(Intent.EXTRA_PHONE_NUMBER);
try {
for(int i=0;i<getUsersPhoneNumbers.size();i++)
{
if(phonenumber.equals(getUsersPhoneNumbers.get(i)))
{
find=true;
break;
}
}
if (!find)
return;
}catch (Exception e) {
phonenumber="";
}
if (!find)
return;
/* examine the state of the phone that caused this receiver to fire off */
String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
logMe("Phone Ringing: the phone is ringing, scheduling creation call answer screen activity");
Intent i = new Intent(context, CallAnswerIntentService.class);
i.putExtra("delay", 100L);
i.putExtra("number", incommingNumber);
context.startService(i);
logMe("Phone Ringing: started, time to go back to listening");
}
if (phone_state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
Intent i = new Intent(context,InCallScreenGuardService.class);
i.putExtra("delay", 100L);
i.putExtra("number", phonenumber);
logMe("Phone Offhook: starting screen guard service");
context.startService(i);
}
if (phone_state.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
Intent i = new Intent(context,InCallScreenGuardService.class);
logMe("Phone Idle: stopping screen guard service");
context.stopService(i);
}
return;
}
The problem:
I can get incoming numbers but I can't get outgoing numbers?
You will need a BroadcastReciever for this.
public class OutgoingCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("OutgoingCallReceiver",phonenumber);
Log.i("OutgoingCallReceiver",bundle.toString());
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}