【问题标题】:How can start a widget from an activity? Intent doesn't work如何从活动启动小部件?意图不起作用
【发布时间】:2017-11-02 23:52:41
【问题描述】:

我有一个名为“recordWidget.java”的小部件,我希望它在主屏幕上打开。

当用户单击名为“recordScreenButton”的按钮时,我希望它转到主屏幕并立即在主屏幕上打开小部件。

public void recordScreenClick(View v) {
        if (v.getId() == R.id.recordScreenButton) { //if they click create
            finish();
            Intent intent = new Intent(Intent.ACTION_MAIN); //goes to homescreen
            Intent i = new Intent(create.this, 
            recordScreenActivity.class);
            Intent widget = new Intent(create.this,recordWidget.class);
            intent.addCategory(Intent.CATEGORY_HOME);
            startActivity(intent);
            startActivity(i);
            startActivity(widget);
    }


}

我以为我可以像任何其他活动一样有意识地打开它,但我不能。除了意图,我还能使用什么?

【问题讨论】:

  • 看起来我难倒了 stackoverflow.. 该死的。

标签: android widget


【解决方案1】:

您无法在奥利奥之前的设备上使用此逻辑。 O 上的新 API 可让您以编程方式在主屏幕上制作小部件。看看我以前的answer

【讨论】:

    猜你喜欢
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    相关资源
    最近更新 更多