I am developing an application for android in which I need to make a call with MMI code in the background of the application. But by default the call application of the android phone is activated and I have to press call button from there. so I want solution for this....
You can try the given simple code this is directly initiating a call to the no provided in code 123456789 and no call button is clicked for this. And yes dont forget to add permission in manifest file:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Throwable e = null;
Log.e("helloandroid dialing example", "Call failed", e);
}
}});
}
If you would have provided some code than it would be helpful other wise have you declared in your app manifest file about the permission to modify phone state.
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"></uses-permission>
Related
I'm currently working on my 2nd program and stuck with phone calling, sending SMS, emailing, and showing location using Google Map. I'm using ImageButtons for all of these. User doesn't need to type any numbers or addresses (not using EditText to get user input). However, it doesn't work.
For example, when user click on Phone icon, it will make a call. However, I still need a user input (the actual message, not the destination number or email address) for sending SMS and email. I can do it if I use EditText. However, without using EditText, I cannot do it. How do I do this? I've added users permission in manifest file.
PhoneActivity .java
public class PhoneActivity extends Activity {
ImageButton btnphonecall;
String phoneNumber = "091111111";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_phone);
btnphonecall=(ImageButton)findViewById(R.id.imageButton1);
btnphonecall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("091111111"));
PhoneActivity.this.startActivity(i);
//I've tried startActivity(i) along but still doesn't work
}
});
}
Use this:
Uri number = Uri.parse("tel:"+091111111 );
Intent dial = new Intent(Intent.ACTION_CALL,
number);
dial.setPackage("com.android.phone");
PhoneActivity.this.startActivity(dial);
Try this:
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneNumber));
startActivity(callIntent);
As we can send data from one Activity to another within the app and also from one app to another app by using Intent
I'm able to send data from my one app to another by using following code
just consider there are two apps APP1 and APP2 and I'm sending data from APP1 to APP2 and vice verse.
In APP1 package name: (com.sush.myApp)
public class HomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// to receive data from com.my.demo package and display it to TextView
TextView mText = (TextView)findViewById(R.id.textView1);
String name=getIntent().getStringExtra("User_Message");
mText.setText(name);
// to send data from com.sush.myApp package to com.my.demo package
Button btn1 =(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.my.demo");
i.putExtra("User_ID", "sush19");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "App Not Found", Toast.LENGTH_LONG).show();
}
}
});
}
and from APP2 package name: (com.my.demo)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to receive data from com.sush.myApp package and display it to TextView
final TextView txt1 = (TextView)findViewById(R.id.Text1);
String name=getIntent().getStringExtra("User_ID");
txt1.setText(name);
// to send data from com.my.demo package to com.sush.myApp package
Button btnSending = (Button)findViewById(R.id.btnSend);
final EditText myMessage = (EditText)findViewById(R.id.txtMessage);
btnSending.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (myMessage.getText().toString().equals(""))
{
Toast.makeText(v.getContext(), "Enter your message", Toast.LENGTH_SHORT).show();
}
else
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.sush.myApp");
i.putExtra("User_Message", myMessage.getText().toString());
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
});
}
And its working perfect..
Now my problem is I want to do same operation i.e sending data from one app to another but my first app is in Java created using Eclipse and my second app is in ActionScript created using AIR for Android in Adobe Flash Professional CS6
Is there a way to use Intent and PackageManager in Actionscript so that I can send the data easily from AIR app to Android App, if yes then can anyone show me a example
Or else can anyone show me an example on how to send data from Android App to AIR for Android App and vice verse..
Thank you...
There's 2 methods I can think of for this.
The first is to use the Java code you have written (or similar), package it as a Native Extension, and build that into your app.
Another alternative is to use a URI scheme and read the data from the InvokeEvent. This SO question covers that method already.
i'm still new and totally noob so please carry on with me .
how to open a link when button clicked in android?
one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
Edit: i'm using phonegap plugin . thanks
Write this code inside onClick :
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Also add the following line to your manifest.xml because you need to have Internet permission to actually use the internet :
<uses-permission android:name="android.permission.INTERNET" />
Read more about Android Permissions.
To read more about Uri refer this link. Also read how Intents work in Android.
Since you are using PhoneGap, un-comment either of the methods below:
one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//super.loadUrl("www.google.com");
// or
//loadUril("www.google.com");
}
});
Hi I'm making an App that checks internet connection, if it's not connected it goes to an activity that has an error message and a button that I want to link to the wireless and network settings. But I'm not sure how to do it, can anyone help me ?
Here's what I've got so far.
public class NetworkActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.networkact);
Button settings = (Button) findViewById(R.id.btn_settings);
// Listening to button event
settings.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Starting a new Intent
Intent gotoSettings = new Intent(getApplicationContext(),
HomeActivity.class);
startActivity(gotoSettings);
}
});
}
}
At the moment it goes to another activity but I want it to go to the wireless & network settings.
I believe, what you want is this:
btn = (Button)this.findViewById(R.id.ButtonNet);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(intent);
}
});
If you use Settings.ACTION_SETTINGS then user can go in both settings mobile network and wifi.
you can use this code for open page mobile network
startActivity(new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS));
I have a small piece of code which is basically supposed to make a phone call when a button is pushed. I looked it up online and all the sources basically gave the same code. But for some reason this code doesn't work. It makes the app crash but the LogCat doesn't display anything (meaning the log is completely blank). I should also mention that in my manifest file I did add the following permission
<uses-permission android:name = "andriod.permission.CALL_PHONE" />
The code I have is as follows. Any help would be greatly appreciated!
phoneButton.setOnClickListener(new OnClickListener () {
public void onClick(View v) {
try {
final Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:232131232"));
ContactUs.this.startActivity(callIntent);
}catch (ActivityNotFoundException e){
Log.e("Dialing", "call Failed!", e);
}
}
});
You spelt android wrong the second time...
Sounds like you need to add the user-permission for making a phone call. I believe the permission is:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
in your manifest file.
This is a snippet from an Activity class I am currently testing on my HTC Desire -
okButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + getPhoneNumber()));
startActivity(intent);
}
});
I suggest changing ContactUs.this.startActivity(callIntent); to startActivity(callIntent); and testing it again.