I want call the function startActivity in two ways:
First (It works):
public class HelloWorld extends Activity
{
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == 1){
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:660718109")));
}
else {
return super.onOptionsItemSelected(item);
}
return true;
}
Second: in HelloActivity.java
public class HelloWorld extends Activity {
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == 1){
IntentsUtils.tryOneOfThese(this);
}
else {
return super.onOptionsItemSelected(item);
}
return true;
}
in IntentsUtils.java
public class IntentsUtils
{
public static void tryOneOfThese(Activity activity)
{
IntentsUtils.call(activity);
}
public static void call(Activity activity)
{
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:5555555555"));
Log.v("MyLogs", "It's works!");
activity.startActivity(intent);
}
}
The second way doesn't work - I have a error in aplication when I clicked on position in menu. I know function "call" in IntentsUtils work because analise logs in "LogCat"
This is my logs from LogCat: android.permission.CALL_PHONE
android.permission.CALL_PHONE> 10-27 16:10:56.702:
WARN/ActivityManager(52): Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5555555555 flg=0x10000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43dbf4b8 363:com.androidbook/10025} (pid=363, uid=10025) requires android.permission.CALL_PHONE
10-27 16:10:56.722: WARN/dalvikvm(363): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
10-27 16:10:56.722: ERROR/AndroidRuntime(363): Uncaught handler: thread main exiting due to uncaught exception
10-27 16:10:56.752: ERROR/AndroidRuntime(363): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:5555555555 flg=0x10000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43dbf4b8 363:com.androidbook/10025} (pid=363, uid=10025) requires android.permission.CALL_PHONEandroid.permission.CALL_PHONE
Thanks in advance, Michael