下面列出了android.content.pm.ShortcutManager#reportShortcutUsed() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String action = getIntent().getAction();
if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
setResult(Activity.RESULT_OK, new Intent()
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class))
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)));
finish();
} else {
mServiceBoundContext.attachService();
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("toggle");
}
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scanner);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getTitle());
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
navigateUp();
}
});
scannerView = (ZXingScannerView) findViewById(R.id.scanner);
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("scan");
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String action = getIntent().getAction();
if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
setResult(Activity.RESULT_OK, new Intent()
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class))
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)));
finish();
} else {
mServiceBoundContext.attachService();
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("toggle");
}
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scanner);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getTitle());
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
navigateUp();
}
});
scannerView = (ZXingScannerView) findViewById(R.id.scanner);
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("scan");
}
}
}
public static void reportAppShortcutUsage(Context context, String remoteName) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
return;
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Set<String> appShortcutIds = sharedPreferences.getStringSet(context.getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>());
String id = getUniqueIdFromString(remoteName);
if (appShortcutIds.contains(id)) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager == null) {
return;
}
shortcutManager.reportShortcutUsed(id);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wechat_contacts);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
WechatFriendArrayList = MyApplication.getInstance().getWechatFriendArrayList();
WechatFriendGroups = MyApplication.getInstance().getWechatFriendGroups();
init();
// Android 7.1 用于提升Shortcut启动性能
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager mShortcutManager = getSystemService(ShortcutManager.class);
mShortcutManager.reportShortcutUsed("static_wechat_contacts");
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_quick_switch);
profilesAdapter = new ProfilesAdapter();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.quick_switch);
RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
LinearLayoutManager lm = new LinearLayoutManager(this);
profilesList.setLayoutManager(lm);
profilesList.setItemAnimator(new DefaultItemAnimator());
profilesList.setAdapter(profilesAdapter);
if (app.profileId() >= 0) {
int position = 0;
List<Profile> profiles = profilesAdapter.profiles;
for (int i = 0; i < profiles.size(); i++) {
Profile profile = profiles.get(i);
if (profile.id == app.profileId()) {
position = i + 1;
break;
}
}
lm.scrollToPosition(position);
}
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("switch");
}
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_quick_switch);
profilesAdapter = new ProfilesAdapter();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.quick_switch);
RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
LinearLayoutManager lm = new LinearLayoutManager(this);
profilesList.setLayoutManager(lm);
profilesList.setItemAnimator(new DefaultItemAnimator());
profilesList.setAdapter(profilesAdapter);
if (ShadowsocksApplication.app.profileId() >= 0) {
int position = 0;
List<Profile> profiles = profilesAdapter.profiles;
for (int i = 0; i < profiles.size(); i++) {
Profile profile = profiles.get(i);
if (profile.id == ShadowsocksApplication.app.profileId()) {
position = i + 1;
break;
}
}
lm.scrollToPosition(position);
}
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager service = getSystemService(ShortcutManager.class);
if (service != null) {
service.reportShortcutUsed("switch");
}
}
}
/**
* Call to report a shortcut used.
* You may call this using any api level.
*
* @param context to access system services
* @param channelId id of the channel that has been selected
*/
public static void reportShortcutUsageGuarded(Context context, String channelId) {
if (areShortcutsSupported()) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
shortcutManager.reportShortcutUsed(channelId);
}
}
}
private void dealWithShortcuts() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager =
getApplicationContext().getSystemService(ShortcutManager.class);
Intent fromShortcut = getIntent();
if (fromShortcut != null) {
if (fromShortcut.hasExtra("search")) {
if (fromShortcut.getBooleanExtra("search", false)) {
shortcutNavigation = true;
if (shortcutManager != null) {
shortcutManager.reportShortcutUsed("search");
}
}
} else if (fromShortcut.hasExtra("timeline")) {
if (fromShortcut.getBooleanExtra("timeline", false)) {
shortcutNavigation = true;
if (shortcutManager != null) {
shortcutManager.reportShortcutUsed("timeline");
}
}
}
}
}
return;
}
@TargetApi(25)
public void report(Contact contact) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(getShortcutId(contact));
}
}
/**
* Reports that a new tab launcher shortcut was selected or an action equivalent to a shortcut
* was performed.
* @param isIncognito Whether the shortcut or action created a new incognito tab.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
private void reportNewTabShortcutUsed(boolean isIncognito) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(
isIncognito ? "new-incognito-tab-shortcut" : "new-tab-shortcut");
}
@TargetApi(25)
public void report(Contact contact) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(getShortcutId(contact));
}
}
@RequiresApi(Build.VERSION_CODES.N_MR1)
private void updateShortCutUsage(VpnProfile profile) {
if (profile == null)
return;
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(profile.getUUIDString());
}
private void reportShortcutUsed(String shortcutId) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
shortcutManager.reportShortcutUsed(shortcutId);
}
}
public static void reportShortcutUsage(Context context, @StringRes int shortcutId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
shortcutManager.reportShortcutUsed(context.getString(shortcutId));
}
}
@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);
}
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportSearchUsed(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(SEARCH_SHORTCUT_ID);
}