'Action Dial works but Action Call gives issue and doesn't do what I want
This code works like a charm but at dial screen i want it to auto make call. however i have changed ACTION_DIAL to ACTION CALL and still no luck. I have give full access in manifest but still not doing what i want it to. please help.
EditText firstNumber;
Button btnAdd;
int number = 35;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main23);
Toast.makeText(Main23Activity.this,
"Type in your Pin Number", Toast.LENGTH_LONG).show();
btnAdd = (Button)findViewById(R.id.button12);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
EditText et = (EditText) findViewById(R.id.editText6);
String text= et.getEditableText().toString();
String character = Character.toString((char) number);
Toast.makeText(Main23Activity.this,
"Adding Money to your account has never been this easy", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + Uri.encode("*221*" + text + "#")));
startActivity(intent);
} catch (Exception e) {
}
}
});
}
}
MANIFEST FILE
<uses-permission android:name="android.permission.CALL_PHONE">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="Splashscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity" />
<activity android:name=".Main22Activity" />
<activity android:name=".Main23Activity" >
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Solution 1:[1]
Dial like this below and don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
Solution 2:[2]
Kotlin code:
fun makeCall(){
val phoneNumber = "12345678"
val dialIntent = Intent(Intent.ACTION_DIAL)
dialIntent.data =
Uri.parse("tel:$phoneNumber")
startActivity(dialIntent)
}
Then call the function:
binding.buttonCall.setOnClickListener{
makeCall() }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | univ |
Solution 2 | Daniela Ramirez Gomez |