如何创建一个快捷方式,当我触摸某个东西时只吐司它
我想在Android中创建一个快捷方式,当我触摸它时,它只会默默地执行一些操作,例如Toast
某些操作。但我发现它会显示主要的Activity
。我怎样才能让它安静地运行?
就像AdvancedTaskManager的快捷方式一样~单击然后Toast
。
谢谢。
目前,我有:
public class ShortcutOnclickActivity extends Activity {
private static final String tag = ShortcutOnclickActivity.class
.getSimpleName();
public static final String ACTION_SHORTCUT_CLICKED = ShortcutOnclickActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show();
Log.d(tag, "Clicked!");
finish();
super.onCreate(savedInstanceState);
return;
}
}
<!-- Shortcut -->
<activity android:name=".ShortcutActivity"
android:screenOrientation="portrait">
</activity>
<activity-alias android:name="CreateShortcutActivity"
android:targetActivity=".ShortcutActivity">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>
</activity-alias>
<activity android:name=".ShortcutOnclickActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.androidesk.ShortcutOnclickActivity" />
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>
</activity>
I want to create a shortcut in Android, and when I touch it, it will only do something silently such as Toast
something. But I found that it will display the main Activity
. How could I get it to run silently?
Just like the AdvancedTaskManager's shortcut~Click and then Toast
.
Thanks.
At the moment, I've got:
public class ShortcutOnclickActivity extends Activity {
private static final String tag = ShortcutOnclickActivity.class
.getSimpleName();
public static final String ACTION_SHORTCUT_CLICKED = ShortcutOnclickActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show();
Log.d(tag, "Clicked!");
finish();
super.onCreate(savedInstanceState);
return;
}
}
<!-- Shortcut -->
<activity android:name=".ShortcutActivity"
android:screenOrientation="portrait">
</activity>
<activity-alias android:name="CreateShortcutActivity"
android:targetActivity=".ShortcutActivity">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>
</activity-alias>
<activity android:name=".ShortcutOnclickActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.androidesk.ShortcutOnclickActivity" />
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>
</activity>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你好,我有同样的问题。
我找到了一个解决方案:
这将正常启动活动,但会隐藏窗口(使其不可见)。
希望这有帮助。
此致,
普达图尔
Hello i had the same problem.
I have found a solution:
This will start the Activity normaly but will hide the window (make it invisible).
hope this helps.
best regards,
PrDatur