Example usage for android.content Intent setPackage

List of usage examples for android.content Intent setPackage

Introduction

In this page you can find the example usage for android.content Intent setPackage.

Prototype

public @NonNull Intent setPackage(@Nullable String packageName) 

Source Link

Document

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.

Usage

From source file:com.cdvdev.subscriptiondemo.helpers.IabHelper.java

/**
 * Setup in-app billing//from w  w  w  .  j a v  a 2  s .co  m
 */
public void startSetup(final OnIabSetupFinishListener finishListener) {
    logDebug("Starting in-app billing setup.");
    checkNotDisposed();
    // If already set up, can't do it again.
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Binding to IInAppBillingService
    mServiceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mIInAppBillingService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();

            try {
                logDebug("Checking for in-app billing 3 support.");
                //check for in-app billing v3 support
                int response = mIInAppBillingService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (finishListener != null) {
                        finishListener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));
                    }

                    // if in-app purchases aren't supported, neither are subscriptions
                    mSubscriptionsSupported = false;
                    mSubscriptionUpdateSupported = false;
                    return;
                } else {
                    logDebug("In-app billing version 3 supported for " + packageName);
                }

                // Check for v5 subscriptions support. This is needed for
                // getBuyIntentToReplaceSku which allows for subscription update
                response = mIInAppBillingService.isBillingSupported(5, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscription re-signup AVAILABLE.");
                    mSubscriptionUpdateSupported = true;
                } else {
                    logDebug("Subscription re-signup not available.");
                    mSubscriptionUpdateSupported = false;
                }

                if (mSubscriptionUpdateSupported) {
                    mSubscriptionsSupported = true;
                } else {
                    // check for v3 subscriptions support
                    response = mIInAppBillingService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                    if (response == BILLING_RESPONSE_RESULT_OK) {
                        logDebug("Subscriptions AVAILABLE.");
                        mSubscriptionsSupported = true;
                    } else {
                        logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                        mSubscriptionsSupported = false;
                        mSubscriptionUpdateSupported = false;
                    }
                }

                mSetupDone = true;

            } catch (RemoteException e) {
                if (finishListener != null) {
                    finishListener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (finishListener != null) {
                finishListener
                        .onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mIInAppBillingService = null;
        }
    };

    //create service
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
        mContext.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (finishListener != null) {
            finishListener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    "Billing service unavailable on device."));
        }
    }

}

From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

/**
 * Create a chooser intent to select the source to get image from.<br/>
 * The source can be camera's (ACTION_IMAGE_CAPTURE) or gallery's (ACTION_GET_CONTENT).<br/>
 * All possible sources are added to the intent chooser.
 *//*w  w w .  jav  a 2  s .  c  o  m*/
public Intent getPickImageChooserIntent() {

    List<Intent> allIntents = new ArrayList<>();
    PackageManager packageManager = getPackageManager();

    // collect all gallery intents
    Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
    galleryIntent.setType("image/*");
    List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0);
    for (ResolveInfo res : listGallery) {
        Intent intent = new Intent(galleryIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(res.activityInfo.packageName);
        allIntents.add(intent);
    }

    // the main intent is the last in the list (fucking android) so pickup the useless one
    Intent mainIntent = allIntents.get(allIntents.size() - 1);
    for (Intent intent : allIntents) {
        if (intent.getComponent().getClassName().equals("com.android.documentsui.DocumentsActivity")) {
            mainIntent = intent;
            break;
        }
    }
    allIntents.remove(mainIntent);

    // Create a chooser from the main intent
    Intent chooserIntent = Intent.createChooser(mainIntent, getString(R.string.choose_photos));

    // Add all other intents
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));

    return chooserIntent;
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)/*from   w  w w . j a  v a2 s  .  co  m*/
@Override
public boolean onPreferenceClick(Preference p) {
    UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    boolean appIsValid = isStartButton || isOverflowMenu
            || !launcherApps.getActivityList(getIntent().getStringExtra("package_name"),
                    userManager.getUserForSerialNumber(userId)).isEmpty();

    if (appIsValid)
        switch (p.getKey()) {
        case "app_info":
            startFreeformActivity();
            launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(componentName),
                    userManager.getUserForSerialNumber(userId), null, null);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "uninstall":
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode()) {
                Intent intent2 = new Intent(ContextMenuActivity.this, DummyActivity.class);
                intent2.putExtra("uninstall", packageName);
                intent2.putExtra("user_id", userId);

                startFreeformActivity();
                startActivity(intent2);
            } else {
                startFreeformActivity();

                Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName));
                intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(userId));

                try {
                    startActivity(intent2);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "open_taskbar_settings":
            startFreeformActivity();

            Intent intent2 = new Intent(this, MainActivity.class);
            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent2);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "quit_taskbar":
            Intent quitIntent = new Intent("com.farmerbb.taskbar.QUIT");
            quitIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(quitIntent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "pin_app":
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
            if (pba.isPinned(componentName))
                pba.removePinnedApp(this, componentName);
            else {
                Intent intent = new Intent();
                intent.setComponent(ComponentName.unflattenFromString(componentName));

                LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent,
                        userManager.getUserForSerialNumber(userId));
                if (appInfo != null) {
                    AppEntry newEntry = new AppEntry(packageName, componentName, appName,
                            IconCache.getInstance(this).getIcon(this, getPackageManager(), appInfo), true);

                    newEntry.setUserId(userId);
                    pba.addPinnedApp(this, newEntry);
                }
            }
            break;
        case "block_app":
            PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this);
            if (pba2.isBlocked(componentName))
                pba2.removeBlockedApp(this, componentName);
            else {
                pba2.addBlockedApp(this, new AppEntry(packageName, componentName, appName, null, false));
            }
            break;
        case "show_window_sizes":
            getPreferenceScreen().removeAll();

            addPreferencesFromResource(R.xml.pref_context_menu_window_size_list);
            findPreference("window_size_standard").setOnPreferenceClickListener(this);
            findPreference("window_size_large").setOnPreferenceClickListener(this);
            findPreference("window_size_fullscreen").setOnPreferenceClickListener(this);
            findPreference("window_size_half_left").setOnPreferenceClickListener(this);
            findPreference("window_size_half_right").setOnPreferenceClickListener(this);
            findPreference("window_size_phone_size").setOnPreferenceClickListener(this);

            SharedPreferences pref = U.getSharedPreferences(this);
            if (pref.getBoolean("save_window_sizes", true)) {
                String windowSizePref = SavedWindowSizes.getInstance(this).getWindowSize(this, packageName);
                CharSequence title = findPreference("window_size_" + windowSizePref).getTitle();
                findPreference("window_size_" + windowSizePref).setTitle('\u2713' + " " + title);
            }

            if (U.isOPreview()) {
                U.showToast(this, R.string.window_sizes_not_available);
            }

            secondaryMenu = true;
            break;
        case "window_size_standard":
        case "window_size_large":
        case "window_size_fullscreen":
        case "window_size_half_left":
        case "window_size_half_right":
        case "window_size_phone_size":
            String windowSize = p.getKey().replace("window_size_", "");

            SharedPreferences pref2 = U.getSharedPreferences(this);
            if (pref2.getBoolean("save_window_sizes", true)) {
                SavedWindowSizes.getInstance(this).setWindowSize(this, packageName, windowSize);
            }

            startFreeformActivity();
            U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "app_shortcuts":
            getPreferenceScreen().removeAll();
            generateShortcuts();

            secondaryMenu = true;
            break;
        case "shortcut_1":
        case "shortcut_2":
        case "shortcut_3":
        case "shortcut_4":
        case "shortcut_5":
            U.startShortcut(getApplicationContext(), packageName, componentName,
                    shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1));

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "start_menu_apps":
            startFreeformActivity();

            Intent intent = null;

            SharedPreferences pref3 = U.getSharedPreferences(this);
            switch (pref3.getString("theme", "light")) {
            case "light":
                intent = new Intent(this, SelectAppActivity.class);
                break;
            case "dark":
                intent = new Intent(this, SelectAppActivityDark.class);
                break;
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref3.getBoolean("freeform_hack", false)
                    && intent != null && isInMultiWindowMode()) {
                intent.putExtra("no_shadow", true);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);

                U.launchAppMaximized(getApplicationContext(), intent);
            } else
                startActivity(intent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "volume":
            AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
            audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE,
                    AudioManager.FLAG_SHOW_UI);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "file_manager":
            Intent fileManagerIntent;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                startFreeformActivity();
                fileManagerIntent = new Intent("android.provider.action.BROWSE");
            } else {
                fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT");
                fileManagerIntent.setComponent(
                        ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity"));
            }

            fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT);
            fileManagerIntent
                    .setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));

            try {
                startActivity(fileManagerIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "system_settings":
            startFreeformActivity();

            Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);

            try {
                startActivity(settingsIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "lock_device":
            U.lockDevice(this);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "power_menu":
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "change_wallpaper":
            Intent intent3 = Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
                    getString(R.string.set_wallpaper));
            intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            U.launchAppMaximized(getApplicationContext(), intent3);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        }

    if (!secondaryMenu)
        finish();
    return true;
}

From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java

@Override
public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException {
    /* System notification case */
    if (content.isSystemNotification()) {
        /* Big picture handling */
        Bitmap bigPicture = null;//from ww  w  .  jav  a 2s. c  o m
        String bigPictureURL = content.getNotificationBigPicture();
        if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) {
            /* Schedule picture download if needed, or load picture if download completed. */
            Long downloadId = content.getDownloadId();
            if (downloadId == null) {
                EngagementNotificationUtilsV11.downloadBigPicture(mContext, content);
                return null;
            } else
                bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId);
        }

        /* Generate notification identifier */
        int notificationId = getNotificationId(content);

        /* Build notification using support lib to manage compatibility with old Android versions */
        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

        /* Icon for ticker and content icon */
        builder.setSmallIcon(mNotificationIcon);

        /*
         * Large icon, handled only since API Level 11 (needs down scaling if too large because it's
         * cropped otherwise by the system).
         */
        Bitmap notificationImage = content.getNotificationImage();
        if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage));

        /* Texts */
        String notificationTitle = content.getNotificationTitle();
        String notificationMessage = content.getNotificationMessage();
        String notificationBigText = content.getNotificationBigText();
        builder.setContentTitle(notificationTitle);
        builder.setContentText(notificationMessage);

        /*
         * Replay: display original date and don't replay all the tickers (be as quiet as possible
         * when replaying).
         */
        Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate();
        if (notificationFirstDisplayedDate != null)
            builder.setWhen(notificationFirstDisplayedDate);
        else
            builder.setTicker(notificationTitle);

        /* Big picture */
        if (bigPicture != null)
            builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle)
                    .setSummaryText(notificationMessage));

        /* Big text */
        else if (notificationBigText != null)
            builder.setStyle(new BigTextStyle().bigText(notificationBigText));

        /* Vibration/sound if not a replay */
        if (notificationFirstDisplayedDate == null) {
            int defaults = 0;
            if (content.isNotificationSound())
                defaults |= Notification.DEFAULT_SOUND;
            if (content.isNotificationVibrate())
                defaults |= Notification.DEFAULT_VIBRATE;
            builder.setDefaults(defaults);
        }

        /* Launch the receiver on action */
        Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION);
        com.microsoft.azure.engagement.reach.EngagementReachAgent.setContentIdExtra(actionIntent, content);
        actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
        Intent intent = content.getIntent();
        if (intent != null)
            actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent());
        actionIntent.setPackage(mContext.getPackageName());
        PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(),
                actionIntent, FLAG_CANCEL_CURRENT);
        builder.setContentIntent(contentIntent);

        /* Also launch receiver if the notification is exited (clear button) */
        Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION);
        exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
        EngagementReachAgent.setContentIdExtra(exitIntent, content);
        exitIntent.setPackage(mContext.getPackageName());
        PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(),
                exitIntent, FLAG_CANCEL_CURRENT);
        builder.setDeleteIntent(deleteIntent);

        /* Can be dismissed ? */
        Notification notification = builder.build();
        if (!content.isNotificationCloseable())
            notification.flags |= Notification.FLAG_NO_CLEAR;

        /* Allow overriding */
        if (onNotificationPrepared(notification, content))

            /*
             * Submit notification, replacing the previous one if any (this should happen only if the
             * application process is restarted).
             */
            mNotificationManager.notify(notificationId, notification);
    }

    /* Activity embedded notification case */
    else {
        /* Get activity */
        Activity activity = EngagementActivityManager.getInstance().getCurrentActivity().get();

        /* Cannot notify in app if no activity provided */
        if (activity == null)
            return false;

        /* Get notification area */
        String category = content.getCategory();
        int areaId = getInAppAreaId(category);
        View notificationAreaView = activity.findViewById(areaId);

        /* No notification area, check if we can install overlay */
        if (notificationAreaView == null) {
            /* Check overlay is not disabled in this activity */
            Bundle activityConfig = EngagementUtils.getActivityMetaData(activity);
            if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true))
                return false;

            /* Inflate overlay layout and get reference to notification area */
            View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null);
            activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
            notificationAreaView = activity.findViewById(areaId);
        }

        /* Otherwise check if there is an overlay containing the area to restore visibility */
        else {
            View overlay = activity.findViewById(getOverlayViewId(category));
            if (overlay != null)
                overlay.setVisibility(View.VISIBLE);
        }

        /* Make the notification area visible */
        notificationAreaView.setVisibility(View.VISIBLE);

        /* Prepare area */
        prepareInAppArea(content, notificationAreaView);
    }

    /* Success */
    return true;
}

From source file:com.android.mail.utils.NotificationUtils.java

public static void sendSetNewEmailIndicatorIntent(Context context, final int unreadCount, final int unseenCount,
        final Account account, final Folder folder, final boolean getAttention) {
    LogUtils.i(LOG_TAG, "sendSetNewEmailIndicator account: %s, folder: %s",
            LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()),
            LogUtils.sanitizeName(LOG_TAG, folder.name));

    final Intent intent = new Intent(MailIntentService.ACTION_SEND_SET_NEW_EMAIL_INDICATOR);
    intent.setPackage(context.getPackageName()); // Make sure we only deliver this to ourselves
    intent.putExtra(EXTRA_UNREAD_COUNT, unreadCount);
    intent.putExtra(EXTRA_UNSEEN_COUNT, unseenCount);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account);
    intent.putExtra(Utils.EXTRA_FOLDER, folder);
    intent.putExtra(EXTRA_GET_ATTENTION, getAttention);
    context.startService(intent);/* w  w  w .  j  a va2s  .  c o m*/
}

From source file:com.librelio.activity.BillingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wait_bar);/*from  ww w . j ava  2 s. com*/

    setResult(RESULT_CANCELED);

    if (!isNetworkConnected()) {
        showAlertDialog(CONNECTION_ALERT);
    } else {
        Intent iapIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        iapIntent.setPackage("com.android.vending");
        getContext().bindService(iapIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        if (getIntent().getExtras() != null) {
            fileName = getIntent().getExtras().getString(FILE_NAME_KEY);
            title = getIntent().getExtras().getString(TITLE_KEY);
            subtitle = getIntent().getExtras().getString(SUBTITLE_KEY);
            // Using Locale.US to avoid different results in different
            // locales
            productId = FilenameUtils.getName(fileName).toLowerCase(Locale.US);
            productId = productId.substring(0, productId.indexOf("_.pdf"));
        }
    }
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wait_bar);//  ww w.  j a va  2 s.  c  om

    setResult(RESULT_CANCELED);

    if (!isNetworkConnected()) {
        showAlertDialog(CONNECTION_ALERT);
    } else {
        Intent iapIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        iapIntent.setPackage("com.android.vending");
        getContext().bindService(iapIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        if (getIntent().getExtras() != null) {
            fileName = getIntent().getExtras().getString(FILE_NAME_KEY);
            title = getIntent().getExtras().getString(TITLE_KEY);
            subtitle = getIntent().getExtras().getString(SUBTITLE_KEY);
            // Using Locale.US to avoid different results in different
            // locales
            productId = FilenameUtils.getName(fileName).toLowerCase(Locale.US);
            productId = productId.substring(0, productId.indexOf("_.sqlite"));
        }
    }
}

From source file:de.tudarmstadt.dvs.myhealthassistant.pubsubexample.withfragment.MFragment.java

/**
 * Publishes an event on a specific myHealthHub channel.
 * //from ww  w  .j a v  a  2 s .  co m
 * @param event
 *            that shall be published.
 * @param channel
 *            on which the event shall be published.
 */
private void publishEvent(Event event, String channel) {
    Intent i = new Intent();
    // add event
    i.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, event.getEventType());
    i.putExtra(Event.PARCELABLE_EXTRA_EVENT, event);

    // set channel
    i.setAction(channel);

    // set receiver package
    // i.setPackage("de.tudarmstadt.dvs.myhealthassistant.pubsubexample");
    i.setPackage("de.tudarmstadt.dvs.myhealthassistant.myhealthhub");

    // sent intent
    if (getActivity() != null)
        getActivity().sendBroadcast(i);
    // mAdapter.notifyDataSetChanged();
}

From source file:com.stepinmobile.fantasticbutton.api.ButtonHandle.java

/**
 * This method search in all applications, and if it will find one, which contains in package name parameter <b>type</b>, it will create share intent and return it.
 * In another case, if application wouldn't be found it will return null.
 *
 * @param type part of application package name
 * @param subject title, which would be applied to created share event
 * @param text content, which would be provided into share intent
 * @return created share intent or <b>null</b>, if application wouldn't be found
 *///from  w w  w  .  j a  v  a 2s.  co m
private Intent getShareIntent(String type, String subject, String text) {
    boolean found = false;
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain");

    // gets the list of intents that can be loaded.
    List<ResolveInfo> resInfo = ((Activity) aq.getContext()).getPackageManager().queryIntentActivities(share,
            0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo info : resInfo) {
            if (info.activityInfo.packageName.toLowerCase().contains(type)
                    || info.activityInfo.name.toLowerCase().contains(type)) {
                share.putExtra(Intent.EXTRA_SUBJECT, subject);
                share.putExtra(Intent.EXTRA_TEXT, text);
                share.setPackage(info.activityInfo.packageName);
                found = true;
                break;
            }
        }
        if (!found)
            return null;

        return share;
    }
    return null;
}

From source file:me.trashout.fragment.TrashDetailFragment.java

@OnClick({ R.id.trash_detail_cleaned_btn, R.id.trash_detail_still_here_btn, R.id.trash_detail_more_btn,
        R.id.trash_detail_less_btn, R.id.trash_detail_direction_btn, R.id.trash_detail_create_event_btn,
        R.id.trash_detail_send_notification_btn, R.id.trash_detail_report_as_spam_btn,
        R.id.trash_detail_edit_fab, R.id.trash_detail_image })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.trash_detail_cleaned_btn:
        TrashReportOrEditFragment trashReportOrEditFragmentCleaned = TrashReportOrEditFragment
                .newInstance(mTrash, true, false, false, false);
        getBaseActivity().replaceFragment(trashReportOrEditFragmentCleaned);
        break;/*from  ww w. ja  va 2 s. c  o  m*/
    case R.id.trash_detail_still_here_btn:
        TrashReportOrEditFragment trashReportOrEditFragmentStillHere = TrashReportOrEditFragment
                .newInstance(mTrash, false, true, false, false);
        getBaseActivity().replaceFragment(trashReportOrEditFragmentStillHere);
        break;
    case R.id.trash_detail_more_btn:
        TrashReportOrEditFragment trashReportOrEditFragmentMore = TrashReportOrEditFragment.newInstance(mTrash,
                false, false, true, false);
        getBaseActivity().replaceFragment(trashReportOrEditFragmentMore);
        break;
    case R.id.trash_detail_less_btn:
        TrashReportOrEditFragment trashReportOrEditFragmentLess = TrashReportOrEditFragment.newInstance(mTrash,
                false, false, false, true);
        getBaseActivity().replaceFragment(trashReportOrEditFragmentLess);
        break;
    case R.id.trash_detail_direction_btn:
        if (mTrash != null) {
            Uri gmmIntentUri = Uri.parse("http://maps.google.com/maps?daddr=" + mTrash.getGps().getLat() + ","
                    + mTrash.getGps().getLng());
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(mapIntent);
            }
        }
        break;
    case R.id.trash_detail_create_event_btn:
        EventCreateFragment eventCreateFragment = EventCreateFragment.newInstance(getTrashId(),
                mTrash != null ? mTrash.getPosition() : null);
        eventCreateFragment.setTargetFragment(this, 0);
        getBaseActivity().replaceFragment(eventCreateFragment);
        break;
    case R.id.trash_detail_send_notification_btn:
        sendNotificationEmail();
        break;
    case R.id.trash_detail_report_as_spam_btn:
        if (mTrash != null) {
            MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                    .title(R.string.global_validation_warning).content(R.string.trash_spam_comfirmation)
                    .positiveText(android.R.string.yes).negativeText(android.R.string.cancel).autoDismiss(true)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            showProgressDialog();
                            CreateTrashNewSpamService.startForRequest(getContext(),
                                    TRASH_CREATE_SPAM_REQUEST_ID, mTrash.getActivityId(), user.getId());
                        }
                    }).build();

            dialog.show();
        }
        break;
    case R.id.trash_detail_edit_fab:
        TrashReportOrEditFragment trashReportOrEditFragment = TrashReportOrEditFragment.newInstance(mTrash,
                false, false, false, false);
        getBaseActivity().replaceFragment(trashReportOrEditFragment);
        break;
    case R.id.trash_detail_image:
        if (mTrash != null && mTrash.getImages() != null && !mTrash.getImages().isEmpty()) {
            PhotoFullscreenFragment photoFullscreenFragment = PhotoFullscreenFragment.newInstance(mImages, 0);
            getBaseActivity().replaceFragment(photoFullscreenFragment);
        }
        break;
    }
}