use of android.content.pm.ShortcutManager in project plaid by nickbutcher.
the class ShortcutHelper method reportPostUsed.
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportPostUsed(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(POST_SHORTCUT_ID);
}
use of android.content.pm.ShortcutManager in project plaid by nickbutcher.
the class ShortcutHelper method disablePostShortcut.
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void disablePostShortcut(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.disableShortcuts(DYNAMIC_SHORTCUT_IDS);
}
use of android.content.pm.ShortcutManager in project AndroidDevelop by 7449.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return;
}
List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo blogShortcut = new ShortcutInfo.Builder(this, "blog").setShortLabel("my blog").setLongLabel("我的博客").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://7449.github.io/"))).build();
ShortcutInfo githubShortcut = new ShortcutInfo.Builder(this, "github").setShortLabel("my github").setLongLabel("我的github").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/7449"))).build();
Intent intent = new Intent(this, TestActivity.class);
intent.setAction(Intent.ACTION_VIEW);
ShortcutInfo newActivityShortcut = new ShortcutInfo.Builder(this, "Activity").setShortLabel("newActivity").setLongLabel("newActivity").setDisabledMessage("被删除了").setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).setIntent(intent).build();
shortcutInfoList.add(blogShortcut);
shortcutInfoList.add(githubShortcut);
shortcutInfoList.add(newActivityShortcut);
shortcutManager.setDynamicShortcuts(shortcutInfoList);
findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
List<ShortcutInfo> dynamicShortcuts = shortcutManager.getDynamicShortcuts();
for (int i = 0; i < dynamicShortcuts.size(); i++) {
ShortcutInfo shortcutInfo = dynamicShortcuts.get(i);
if (TextUtils.equals("github", shortcutInfo.getId())) {
//桌面的图标这个时候就变灰了
shortcutManager.disableShortcuts(Collections.singletonList(shortcutInfo.getId()));
shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutInfo.getId()));
}
}
}
}
});
}
use of android.content.pm.ShortcutManager in project android_frameworks_base by DirtyUnicorns.
the class RemoteInputView method sendRemoteInput.
private void sendRemoteInput() {
Bundle results = new Bundle();
results.putString(mRemoteInput.getResultKey(), mEditText.getText().toString());
Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
RemoteInput.addResultsToIntent(mRemoteInputs, fillInIntent, results);
mEditText.setEnabled(false);
mSendButton.setVisibility(INVISIBLE);
mProgressBar.setVisibility(VISIBLE);
mEntry.remoteInputText = mEditText.getText();
mController.addSpinning(mEntry.key, mToken);
mController.removeRemoteInput(mEntry, mToken);
mEditText.mShowImeOnInputConnection = false;
mController.remoteInputSent(mEntry);
// Tell ShortcutManager that this package has been "activated". ShortcutManager
// will reset the throttling for this package.
// Strictly speaking, the intent receiver may be different from the notification publisher,
// but that's an edge case, and also because we can't always know which package will receive
// an intent, so we just reset for the publisher.
getContext().getSystemService(ShortcutManager.class).onApplicationActive(mEntry.notification.getPackageName(), mEntry.notification.getUser().getIdentifier());
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND, mEntry.notification.getPackageName());
try {
mPendingIntent.send(mContext, 0, fillInIntent);
} catch (PendingIntent.CanceledException e) {
Log.i(TAG, "Unable to send remote input result", e);
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_FAIL, mEntry.notification.getPackageName());
}
}
use of android.content.pm.ShortcutManager in project android_frameworks_base by AOSPA.
the class RemoteInputView method sendRemoteInput.
private void sendRemoteInput() {
Bundle results = new Bundle();
results.putString(mRemoteInput.getResultKey(), mEditText.getText().toString());
Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
RemoteInput.addResultsToIntent(mRemoteInputs, fillInIntent, results);
mEditText.setEnabled(false);
mSendButton.setVisibility(INVISIBLE);
mProgressBar.setVisibility(VISIBLE);
mEntry.remoteInputText = mEditText.getText();
mController.addSpinning(mEntry.key, mToken);
mController.removeRemoteInput(mEntry, mToken);
mEditText.mShowImeOnInputConnection = false;
mController.remoteInputSent(mEntry);
// Tell ShortcutManager that this package has been "activated". ShortcutManager
// will reset the throttling for this package.
// Strictly speaking, the intent receiver may be different from the notification publisher,
// but that's an edge case, and also because we can't always know which package will receive
// an intent, so we just reset for the publisher.
getContext().getSystemService(ShortcutManager.class).onApplicationActive(mEntry.notification.getPackageName(), mEntry.notification.getUser().getIdentifier());
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND, mEntry.notification.getPackageName());
try {
mPendingIntent.send(mContext, 0, fillInIntent);
} catch (PendingIntent.CanceledException e) {
Log.i(TAG, "Unable to send remote input result", e);
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_FAIL, mEntry.notification.getPackageName());
}
}
Aggregations