public class ShareTool { public static void share(Context context) { // TODO Auto-generated method stub Intent intent=new Intent(Intent.ACTION_SEND); // 分享的数据类型 intent.setType("text/plain"); // 内容 intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.share_content)); // 目标应用选择对话框的标题 context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_title))); } public static void more(Context context) { if (com.wz.notify.Constant.getChanelSwitch(context).equals("true")) { // TODO Auto-generated method stub String cpaType = OnlineParams.getCpaType(context); if (cpaType.equals("appjoy")) { UUAppConnect.getInstance(context).showOffers(); } else if (cpaType.equals("kuguo")) { KuguoAdsManager.getInstance().showAppList(context); } } } /** * 为程序创建桌面快捷方式 */ public static void addShortcut(Activity activity){ if (!hasShortcut(activity)) { Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); //快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name)); shortcut.putExtra("duplicate", false); //不允许重复创建 //指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer //注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序 ComponentName comp = new ComponentName(activity.getPackageName(), "." + activity.getLocalClassName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent( Intent.ACTION_MAIN).setComponent(comp)); //快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource .fromContext(activity, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); activity.sendBroadcast(shortcut); // 保存创建记录 SharedPreferences sp = PreferenceManager. getDefaultSharedPreferences(activity); Editor editor = sp.edit(); editor.putBoolean("never_check_shortCut", true); editor.commit(); } } /** * 是否已创建快捷方式 * @return */ private static boolean hasShortcut(Activity activity) { SharedPreferences sp = PreferenceManager. getDefaultSharedPreferences(activity); boolean never_check_shortCut = sp.getBoolean ("never_check_shortCut", false); return never_check_shortCut; }
app推广必备功能:分享到,更多应用,创建快捷方式
猜你喜欢
转载自free0coding.iteye.com/blog/1747704
今日推荐
周排行