How to create a shortcut which only Toast something when I touched it
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 silent开发者_如何学Pythonly?
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>
Hello i had the same problem. I have found a solution:
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show();
setVisible(false);
finish();
return;
}
This will start the Activity normaly but will hide the window (make it invisible).
hope this helps.
best regards, PrDatur
精彩评论