I looked at the example here and tried to replicate the answer. However,
Intent callIntent = new Intent(Intent.ACTION_CALL); does nothing while
Intent callIntent = new Intent(Intent.ACTION_DIAL); brings me to the number pad with the pre-set number.
I want it to call the number without bringing me to the number pad. How do I make it work?
the onUpdate():
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
Log.d("HomeWidget", "onUpdate(): ");
for (int appWidgetId : appWidgetIds) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+12345678));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, callIntent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.call, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
Edit
From the answer below, I see that there are restrictions present on Intent.CALL but i really want to use it. Anyone can help me on how to lift the restrictions?
Turns out that all I need is just
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>