如何将活动的快捷方式放入启动器?

发布于 2024-12-14 15:31:29 字数 1865 浏览 5 评论 0原文

我正在尝试做下一个链接中简要描述的事情:

link

意思是,我有一个活动,甚至可以在另一个应用程序上(但现在让我们关注我的应用程序具有的活动),我希望能够创建一个它的捷径。

对于术语来说,假设创建快捷方式的活动名为“ShortcutCreatorActivity”,启动的活动为“MyActivity”。

我从所写的内容中得到的是 ShortcutCreatorActivity 应该在清单中定义为:

<activity android:icon="@drawable/ic_launcher"
  android:label="ShortcutActivity" android:name="com.my_app.ShortcutCreatorActivity">
  <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

我在其 java 代码中得到的是:

public class ShortcutCreatorActivity extends Activity
  {
  @Override
  protected void onCreate(final Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    final Intent shortcutIntent=new Intent("com.my_app.MyActivity");
    final ShortcutIconResource iconResource=Intent.ShortcutIconResource.fromContext(this,R.drawable.ic_launcher);
    final Intent intent=new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"Shortcut Test");
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
    setResult(RESULT_OK,intent);
    Toast.makeText(this,"shortcut created",Toast.LENGTH_SHORT).show();
    finish();
    }
  }

然而,当单击快捷方式时,我不断收到“找不到应用程序”的相同消息,并且日志:

ActivityManager(232): Starting: Intent { act=com.my_app.MyActivity flg=0x10200000 bnds=[80,150][160,250] } from pid 3956

有人可以帮我吗?缺什么? 我还尝试了清单中 MyActivity 活动的一些意图过滤器。没有任何帮助......


@liro 我认为这并不重要,因为我已经指定了类的确切完整路径,包括包名称。


大家,如果你有一个可行的项目,那就完美了。

i'm trying to do something that is described briefly on the next link:

link

meaning, i have an activity that can be even on another application (but for now let's focus on an activity that my app has) , which i want to be able to create a shortcut to it.

for terminology , let's say that the activity that creates the shortcut is named "ShortcutCreatorActivity" ,and the activity that gets started is "MyActivity" .

what i got from what is written is that the ShortcutCreatorActivity should be defined in the manifest as:

<activity android:icon="@drawable/ic_launcher"
  android:label="ShortcutActivity" android:name="com.my_app.ShortcutCreatorActivity">
  <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

and what i got in its java code is:

public class ShortcutCreatorActivity extends Activity
  {
  @Override
  protected void onCreate(final Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    final Intent shortcutIntent=new Intent("com.my_app.MyActivity");
    final ShortcutIconResource iconResource=Intent.ShortcutIconResource.fromContext(this,R.drawable.ic_launcher);
    final Intent intent=new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"Shortcut Test");
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
    setResult(RESULT_OK,intent);
    Toast.makeText(this,"shortcut created",Toast.LENGTH_SHORT).show();
    finish();
    }
  }

yet i keep getting the same message of "application not found" when clicking on the shortcut , and the log :

ActivityManager(232): Starting: Intent { act=com.my_app.MyActivity flg=0x10200000 bnds=[80,150][160,250] } from pid 3956

can anyone please help me? what is missing?
i've also tried some intent filters for the MyActivity activity inside the manifest. nothing helped...


@liro
i don't think it matters , since i've specified the exact full path to the class , including the package name.


everyone, please, if you have a working project, that would be perfect .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

家住魔仙堡 2024-12-21 15:31:29

这里不确定,但我认为您需要从“com.MyActivity”中删除“com”。

<activity android:icon="@drawable/ic_launcher"
  android:label="ShortcutActivity" android:name=".ShortcutCreatorActivity">
   <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

Not sure here, but I think you need to remove the "com" from "com.MyActivity."

<activity android:icon="@drawable/ic_launcher"
  android:label="ShortcutActivity" android:name=".ShortcutCreatorActivity">
   <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>
平生欢 2024-12-21 15:31:29

而不是

final Intent shortcutIntent=new Intent("com.my_app.MyActivity");

尝试

final Intent shortcutIntent=new Intent(this, com.my_app.MyActivity.class);

或在该活动的意图过滤器中定义您的操作,我相信您可能没有这样做。

这两个链接可能会有所帮助:
http://developer.android.com/reference /android/content/Intent.html#Intent(java.lang.String)
http://developer.android.com/guide/topics/manifest/action -element.html

Instead of

final Intent shortcutIntent=new Intent("com.my_app.MyActivity");

try

final Intent shortcutIntent=new Intent(this, com.my_app.MyActivity.class);

or define your action in intent-filter of that activity, which I believe you may did not.

Those two links may be helpful:
http://developer.android.com/reference/android/content/Intent.html#Intent(java.lang.String)
http://developer.android.com/guide/topics/manifest/action-element.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文