是否可以通过在android主屏幕小部件内按下按钮来启动呼叫?在android中启动来自窗口小部件的调用
我有以下的代码,它不工作,按下按钮什么都不做:
public class WidgetTestActivity extends AppWidgetProvider {
@Override
public void onEnabled(Context context)
{
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
String url = "tel:3334444";
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse(url));
PendingIntent call1 = PendingIntent.getBroadcast(context, 0, i, 0);
remoteViews.setOnClickPendingIntent(R.id.button1, call1);
}
}
我的理解是要启动已与Intent.ACTION_CALL,即规定在使用时的意图真正的Activity调用是Intent intent = new Intent(Intent.CALL_ACTION); intent.setData(Uri.parse(“tel:69342”)); startActivity(intent); – SamRowley
你甚至可以自己定义一个Action(它只是一个字符串)。如果是这样,你必须注册AndroidManifest.xml,你正在定义的AppWidgetProvider将使用该特定的意图操作。 remoteViews.setOnClickPendingIntent(..);通过这metohd你设置,当按钮将被点击一个意图,因为指定将被解雇,你可以把你的代码在onRecive检查意图行动...我不知道,如果这是你一直在寻找 –