如何将活动的快捷方式放入启动器?
我正在尝试做下一个链接中简要描述的事情:
意思是,我有一个活动,甚至可以在另一个应用程序上(但现在让我们关注我的应用程序具有的活动),我希望能够创建一个它的捷径。
对于术语来说,假设创建快捷方式的活动名为“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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里不确定,但我认为您需要从“com.MyActivity”中删除“com”。
Not sure here, but I think you need to remove the "com" from "com.MyActivity."
而不是
尝试
或在该活动的意图过滤器中定义您的操作,我相信您可能没有这样做。
这两个链接可能会有所帮助:
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
try
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