I made an android app to call to a number when a message is received using broadcast receiver.
But I am getting an error no activity found to handle the intent. How can I solve this problem?
Code is given below
Intent intent1 = new Intent(Intent.ACTION_CALL);
intent1.setData(Uri.parse(incno1));
context.startActivity(intent1);
I added the line intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);, but this also does not solve my problem.
The protocol is incorrect. You need to do the following:
callIntent.setData(Uri.parse("tel:"+incno1));
And ensure the following permission is set:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Try this code may be working i am not tested:
Intent intent1 = new Intent(Intent.ACTION_CALL);
intent1.setData(Uri.parse("tel:" + incno1));
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.addFlags(Intent.FLAG_FROM_BACKGROUND);
context.startActivity(intent1);
You can add it in your xml file
android:autoLink="phone"
android:phoneNumber="true"
add this to your text view that links directly to call.
try {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:+123456"));
startActivity(intent);
} catch (Exception e) {
Log.e("SampleApp", "Failed to invoke call", e);
}
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
use permission in AndroidManifest.xml
Related
I'm trying to make the application that this CallScreeningService is written in open when the incoming phone number matches certain numbers. In this case the if statement in onScreenCall calls runs but the Activity isn't started. I'm not sure why, I'm guessing it's because I don't have the right context of the application. Does anyone know how I would get the correct context or what i'm doing wrong here?
public class CallScreenService extends CallScreeningService {
Context nContext = this;
#Override
public void onScreenCall(Call.Details callDetails) {
if (callDetails.getHandle().toString().equals("tel:333333333")) {
Intent i = new Intent(nContext, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nContext.startActivity(i);
}
}
}
The app needs to have granted SYSTEM_ALERT_WINDOW permission by the user on Android 10+.
You have to add it in manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
And to request it from user:
// Show alert dialog to the user saying a separate permission is needed
Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(myIntent);
When I try to make a call from my app using
intent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode));
startActivity(intent);
I get the option
I want to programmatically choose the dialer that the user will use to make the call. I want the user to automatically use Phone (the original dialer) instead of Skype or any other option.
From googling, I found this option below but it only allows the developer to make the user choose the developer's own app as a default dialer. I want to programmatically ask the user to choose the original phone's default dialer "Phone" so that the user is no longer asked the question.
From google, I found this link: Programmatically change the "Use by default for this action"
which has this option:
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
} else {
Log.w(getLocalClassName(), "No Intent available to handle action");
}
But what I want is a bit different.
Use the below code:
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
it is working for me
Try This
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + "mobilePhone"));
context.startActivity(intent);
I was having some problem when trying to perform an application upgrade in Android emulator. The flow of the scenario is from an Activity, I will execute AsyncTask A which open up fragment A, then inside AsyncTask A, I will check if version upgrade is available.
If available and user selected "Okay" from fragment A, I will proceed to AsyncTask B to open up fragment B which show a message to user saying that upgrading is in process. In AsyncTask B doInBackground(), I will execute the install() and in onPostExecute(), I will show successful message.
In my AsyncTask B where I execute the install:
#Override
protected Boolean doInBackground(Void... params) {
boolean ret= viewmodel.installApk(mActivity);
return ret;
}
In my view model class:
public boolean installApk(Activity mActivity){
boolean success = false;
String fullPath = scanDirectoryForApk();
System.out.println("INSTALLING APK ......................... ");
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkURI = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".provider", new File(fullPath));
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
return true;
}
However, when I execute the code above, no error message was shown and the version upgrade is not working as well. It basically just restart the intent and there is no upgrade at all.
It does not prompt me for the permission to install new version as well. Any ideas?
By the way, my android emulator is not rooted and therefore I could not use the "su" command approach.
Thanks!
EDIT
As suggestion by #Sagar, I changed my code above to:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkURI = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".provider", new File(fullPath));
List<ResolveInfo> resInfoList = mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
mActivity.grantUriPermission(packageName, apkURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
And I am getting new error message from logcat:
Error staging apk from content URI
java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{3883c8 9647:com.google.android.packageinstaller/u0a20} (pid=9647, uid=10020) that is not exported from UID 10085
The intent error message is telling me "There was a problem parsing package".
You can try to merge
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
into
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
I met the same issue as you, and this solution rescued myself.
I have some problems handling http response codes. The problem is that the app crashes because I do not give a specific function to run.
In this case I want to send the user back to login screen when the Httresponsecode is 401 otherwise the user can still use the app.
In my current code I have the following:
public boolean isUnauthorized(JSONObject response){
try {
if(response.getInt("StatusCode") == 401) {
return true;
}
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
What I want is here is to call so that when calling this function app wide it will do the same on every screen.
Intent i = new Intent(Register.class, Register.activity);
startactivity(i);
However this isn't possible because the ResponseHandler cannot extends Activity. If I do this I get a stack-trace error containing looper.prepare() must be called.
Can you anybody tell me how I can call a new intent from here. The class containing above is in a folder called components and my app activities are in another folder in case it is needed for giving the right answer.
Intent i = new Intent(Register.class, Register.activity);
startactivity(i);
This should be
Intent i = new Intent(CurrentClass.this, Activity.class);
startactivity(i);
if you have fragment
Intent i = new Intent(getActivity(), Activity.class);
getActivity().startactivity(i);
You need to pass the current Activity or the Application Context as argument for your Intent.
If it is inside a fragment then
getActivity().startActivity(getActivity(), newActivity.class);
If it is inside a class then:
context.startActivity(context, newActivity.class);
I'm very much a beginner at this and I'm struggling to get this to work.
When button is pressed, I simply want the dialer to open with the specified number automatically inputted.
So far I've tried the following:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:00000000"));
startActivity(callIntent);
}
});
I've also tried:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneno="00000000";
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse(phoneno));
startActivity(i);
}
});
I've added the permission ACTION_CALL to the manifest.
Whenever I click the Call button the app force closes.
Any assistance would be greatly appreciated.
Thank you!
String number = "12345678";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
You need to add this Permission to your manifest.
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
i think you Must add <uses-permission android:name="android.permission.CALL_PHONE" /> in Manifest.
If you want the dialer to open with the number use ACTION_DIAL
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + phoneno));
You do not need any permission
Make sure you have added the
<uses-permission android:name="android.permission.CALL_PHONE" />
tag at a correct level in the AndroidManifest.xml file (outside the
<application ... /> tag but within the <manifest ... /> tag):
Try this.
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno)));
Also, add the permission android.permission.CALL_PHONE in your manifest file.
Add the following in the manifest file and it should work fine -
<uses-permission android:name="android.permission.CALL_PHONE"/>
In your Android Phone Go to: "Setting"-> "InstalledApp"-> "find your app"-> "App Permission"-> "Here allow the "Telephone Permission"
Hope it will help you