Mange Phone calls in android studio - java

I'm trying to manage phone calls on my app.
I have managed to find this code which starts a phone call
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:"+et.getText().toString()));
startActivity(i);
but no luck in finding how to reject / end a call.
something like a button on my app which will end the current if there is one.
Thanks so much in advance!

Related

How to start an Android App by receiving a SMS?

I have written an Application, which checks when you receive a new SMS and if its from a certain number, the app plays the ringtone. Now, the App should check if there is a new SMS even if it isn´t lauchned, and so my question is: How can I launch my App by receiving a new SMS?
I tryed to upload my existing code but it didn´t worked, I am sorry.
To start an activity from almost everywhere you can simply call:
Intent myIntent = new Intent(CurrentActivity.this, NewActivity.class);
CurrentActivity.this.startActivity(myIntent);
That should also work from your BroadcastReceiver which is triggered while receiving the sms.

Close intent to navigate google and return to my application

I am trying to make an android application, with a button I call google navigation and it works correctly, and my question is: somehow I can close the navigation of google once finished and return to my application?
I do not want to press the back button.
This is the method
Uri gmmIntentUri = Uri.parse("google.navigation:q="+ lat + ","+ lng + ");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK&Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
mapIntent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(mapIntent);
If any application can close other applications then there will be a big question about security.
There is no way to close other applications in Android. Also, you can't get a callback once the navigation finished. I have also faced the same issue and resolved it by ChatHead. When the user taps on ChatHead you can redirect the user to your app.
Here is a reference to create ChatHead: https://medium.com/#kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064

How to read NFC Tag and call Webservice in Android

I'm now developing an android application with the NFC concept . In that application I need to pick my application if I swipe the NFC card and if I select my application my application must start calling webservice.
when it comes to my problem, If suppose my app crashed ,when I swipe the card next time ,the option to choose the application doesn't open .Instead,my application directly launched and couldn't call the webservice data.
On the whole.I'm getting last page when it crashed .But I need to open as fresh
I came to know that I need to make changes in OnResume() and OnNewIntent().
I used ,
In OnResume()
super.onResume();
mNfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, mNdefExchangeFilters, null);
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
NdefMessage[] msgs = getNdefMessages(getIntent());
byte[] payload = msgs[0].getRecords()[0].getPayload();
//Toast.makeText(this, new String(payload), Toast.LENGTH_LONG).show();
Student=new String(payload);
if(Student.equals(rakesh)
{
new Webservice.execute(""); // Calling SOAP Webservice
}
But,I can't find any changes with my problem .and one more thing that the problem will be resolve after I just open and close an another NFC project
Please help.
Yeah ! I got the solution .I forget a simple thing that I left calling onStop() method and my problem was,when my application stops(when Crashed).It runs in background as the previous activity.
I just tried the following,
public void onStop()
{
super.onStop();
this.finish();
}
This may be helpful to others.
Thanks..

Trying to use Zxing QR code reader API results in force close

I have integrated the Zxing API and use this code:
Intent data = new Intent("com.google.zxing.client.android.SCAN");
And getting the result with this code:
String contents = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");
But when I run this code, the app will ask to force close.
When sending an Intent to startActivity(), you must always check if the user has any apps that can handle the intent:
Caution: It's possible that a user won't have any apps that handle the implicit intent you send to startActivity(). If that happens, the call will fail and your app will crash. To verify that an activity will receive the intent, call resolveActivity() on your Intent object. If the result is non-null, then there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that issues the intent.
Go through this. App is crashing because Zxing app is not installed in the mobile. I gave a detailed answer in the same link.

Android, Opening app only if it is closed through intent action

I am working on a phonegap application, with some native pieces.
So far I have notifications running natively, to make sure javascript and phonegap is not required at all. The problem I am having however, is when the notification is clicked I'd like to open the app, or otherwise just bring the app to the front.
How do I do this? I tried setting the main activity in the intent, but it restarts my application every time.
Intent notificationIntent = new Intent(context, main.app.class);
notificationIntent.putExtra(NOTIF_RESPOND, runThis);
notificationIntent.setAction(Intent.ACTION_VIEW);
notificationIntent = notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Actually in Android there is almost no such thing as "restarting application". Basically the Application - is a bundle of all your services/activities/providers etc. It's either running or not.
If user starts a new Activity - system will check, if application is running - it will create this activity inside the application. If no - will create new Application instance.
So I think you mean that if you set intent for your Main activity - another instance of Activity is launching, am I right?
If so - take a look at the following flag for activity, you should try to set in in the Manifest(or whatever in PhoneGap, sorry). http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
<activity android:name=".YourActivity"
android:launchMode="singleTask"
...
This flag will tell the system not to create a new Activity each type it will be needed, but to reuse already-existing one. Be careful, you should properly implement onNewIntent method in this case to handle this "relaunches", and I'm not 100% sure that it's implemented in PhoneGap.
Good luck

Categories