Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

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

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || null == intent.getAction()) {
        Log.i(LOG_TAG, "Received null Foreground Intent ");

        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            if (activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_ALONGWITHINGRESS)) {
                startMonitorIngressRunning();
            }//from w w w.  j  av a  2 s  .co m
        }

    } else if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Start Foreground Intent ");
        overlayView.setVisible();

        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            if (activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_ALONGWITHINGRESS)) {

                startMonitorIngressRunning();
            }
        }

    } else if (intent.getAction().equals(Constants.ACTION.SETTINGS_ACTION)) {
        Log.i(LOG_TAG, "Received Settings Intent");

        Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
        settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity");
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(settingsIntent);

    } else if (intent.getAction().equals(Constants.ACTION.PAUSEFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Pause Foreground Intent");

        overlayView.setInvisible();

    } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Stop Foreground Intent");

        overlayView.setInvisible();
        stopForeground(true);
        stopSelf();
    }
    return START_STICKY;
}

From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java

@Override
protected Notification foregroundNotification(int notificationId) {
    Notification notification;//from  ww w.  j av a2  s  .c o m

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_MANUAL)) {
        Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
        settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity");
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, 0);

        Intent startFgIntent = new Intent(this, CustomOverlayService.class);
        startFgIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION);
        PendingIntent pstartFgIntent = PendingIntent.getService(this, 0, startFgIntent, 0);

        Intent pauseFgIntent = new Intent(this, CustomOverlayService.class);
        pauseFgIntent.setAction(Constants.ACTION.PAUSEFOREGROUND_ACTION);
        PendingIntent ppauseFgIntent = PendingIntent.getService(this, 0, pauseFgIntent, 0);

        Intent stopFgIntent = new Intent(this, CustomOverlayService.class);
        stopFgIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
        PendingIntent pstopFgIntent = PendingIntent.getService(this, 0, stopFgIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

        notification = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.title_notification))
                .setTicker(getString(R.string.title_notification))
                .setContentText(getString(R.string.message_notification)).setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).addAction(android.R.drawable.ic_media_play, "Start", pstartFgIntent)
                .addAction(android.R.drawable.ic_media_pause, "Pause", ppauseFgIntent)
                .addAction(android.R.drawable.ic_delete, "Stop", pstopFgIntent).build();

    } else {
        notification = new Notification(R.drawable.ic_launcher, getString(R.string.title_notification),
                System.currentTimeMillis());

        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_ONLY_ALERT_ONCE;

        notification.setLatestEventInfo(this, getString(R.string.title_notification),
                getString(R.string.message_notification_manual), notificationIntent());
    }
    return notification;
}

From source file:capsrock.beta.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    timeSheet = new TimeSheet();
    PebbleData = new PebbleDictionary();
    //Set up to Receive messages from the pebble and handle them correctly
    PebbleKit.registerReceivedDataHandler(this, new PebbleKit.PebbleDataReceiver(PEBBLE_APP_UUID) {
        @Override/*from  w  w w .j a v  a  2 s . co m*/
        public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
            String mode = data.getString(1);
            //((TextView)findViewById(R.id.pebbleText)).setText(mode);
            if (mode.substring(9).equals("Break") || mode.substring(9).equals("Work")) {
                ((TimeEntryFragment) getSupportFragmentManager()
                        .findFragmentByTag("android:switcher:" + R.id.pager + ":0"))
                                .onTimeEntry(findViewById(R.id.StartButton), false);
            } else {
                ((TimeEntryFragment) getSupportFragmentManager()
                        .findFragmentByTag("android:switcher:" + R.id.pager + ":0"))
                                .onTimeEntry(findViewById(R.id.StopButton), false);
            }
            PebbleKit.sendAckToPebble(getApplicationContext(), transactionId);
        }
    });
    //Set up the timer thread
    thr = new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            Message mes = new Message();
                            if (strDate != null) {
                                long seconds = Calendar.getInstance().getTimeInMillis()
                                        - strDate.getTimeInMillis();
                                long minutes = seconds / 1000 / 60;
                                minutes %= 60;

                                long hours = seconds / 1000 / 60 / 60;
                                hours %= 24;

                                seconds /= 1000;
                                seconds %= 60;

                                String sec = hours + ":" + minutes + ":" + seconds;
                                mes.obj = sec;
                                mHandler.sendMessage(mes);
                            } else {
                                mes.obj = "00:00:00";
                                mHandler.sendMessage(mes);
                            }
                        }
                    });
                } catch (Exception e) {

                }
            }
        }
    });

    //Start Login Screen
    Intent intent = new Intent();
    intent.setClassName("capsrock.beta", "capsrock.beta.LoginActivity");
    //startActivity(intent);
    setContentView(R.layout.activity_main);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);

        }

    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WAccountRegisterFragment.java

/** Execute Signup.*/
private void exeSignup(final String email) {
    HVCManager.INSTANCE.signup(email, new HVCManager.ResponseListener() {
        @Override//w  ww .  ja  va2  s.  c o  m
        public void onReceived(String json) {
            try {
                if (json == null) {
                    HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                            getString(R.string.c2w_setting_error_4), null);
                    return;
                }
                JSONObject jsonObject = new JSONObject(json);
                JSONObject result = jsonObject.getJSONObject("result");
                String code = result.getString("code");
                String msg = result.getString("msg");
                if (BuildConfig.DEBUG) {
                    Log.d("ABC", String.format("response=%s(%s)", code, msg));
                }
                if (msg.equals("success")) {
                    HVCC2WDialogFragment.showConfirmAlert(getActivity(), getString(R.string.hw_name),
                            getString(R.string.c2w_setting_message_2_2), getString(R.string.button_gmail),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Intent intent = new Intent(Intent.ACTION_MAIN);
                                    intent.setAction("android.intent.category.LAUNCHER");
                                    intent.setClassName("com.google.android.gm",
                                            "com.google.android.gm.ConversationListActivityGmail");
                                    intent.setFlags(0x10200000);
                                    startActivity(intent);

                                }
                            });
                } else {
                    HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                            getString(R.string.c2w_setting_error_4), null);
                }
            } catch (JSONException e) {
                if (BuildConfig.DEBUG) {
                    e.printStackTrace();
                }
                HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                        getString(R.string.c2w_setting_error_4), null);

            }
        }
    });
}

From source file:com.sdk.download.providers.downloads.DownloadNotification.java

private void updateActiveNotification(Collection<DownloadInfo> downloads) {
    // Collate the notifications
    mNotifications.clear();/*  ww w.j a v a 2 s.co  m*/

    for (DownloadInfo download : downloads) {
        if (!isActiveAndVisible(download)) {
            continue;
        }

        String packageName = download.mPackage;
        long max = download.mTotalBytes;
        long progress = download.mCurrentBytes;
        long id = download.mId;
        String title = download.mTitle;
        if (title == null || title.length() == 0) {
            title = mContext.getResources().getString(R.string.zuimeia_sdk_download_download_unknown_title);
        }

        synchronized (mNotifications) {
            if (!mNotifications.containsKey(id)) {
                if (download.mStatus == Downloads.STATUS_RUNNING) {
                    NotificationItem item = new NotificationItem();
                    item.mId = id;
                    item.mPackageName = packageName;
                    item.mDescription = download.mDescription;
                    item.mStatus = download.mStatus;
                    item.addItem(title, progress, max);
                    mNotifications.put(download.mId, item);
                    if (download.mStatus == Downloads.STATUS_QUEUED_FOR_WIFI && item.mPausedText == null) {
                        item.mPausedText = mContext.getResources()
                                .getString(R.string.zuimeia_sdk_download_notification_need_wifi_for_size);
                    }
                } else {
                    mSystemFacade.cancelNotification(id);
                }
            }
        }
    }

    // Add the notifications
    for (NotificationItem item : mNotifications.values()) {
        // Build the notification object
        final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
        builder.setPriority(2);
        boolean hasPausedText = (item.mPausedText != null);
        int iconResource = android.R.drawable.stat_sys_download_done;
        if (hasPausedText) {
            iconResource = android.R.drawable.stat_sys_warning;
        }
        builder.setSmallIcon(iconResource);
        builder.setOngoing(true);

        boolean hasContentText = false;
        StringBuilder title = new StringBuilder(item.mTitles[0]);
        if (item.mTitleCount > 1) {
            title.append(mContext.getString(R.string.zuimeia_sdk_download_notification_filename_separator));
            title.append(item.mTitles[1]);
            if (item.mTitleCount > 2) {
                title.append(mContext.getString(R.string.zuimeia_sdk_download_notification_filename_extras,
                        new Object[] { Integer.valueOf(item.mTitleCount - 2) }));
            }
        } else if (!TextUtils.isEmpty(item.mDescription)) {
            builder.setContentText(item.mDescription);
            hasContentText = true;
        }
        builder.setContentTitle(title);// 

        if (hasPausedText) {// ??
            builder.setContentText(item.mPausedText);
        } else {
            builder.setProgress((int) item.mTotalTotal, (int) item.mTotalCurrent, item.mTotalTotal == -1);
            if (Build.VERSION.SDK_INT >= 11) {
                if (hasContentText) {
                    builder.setContentInfo(getDownloadingText(item.mTotalTotal, item.mTotalCurrent));
                }
            } else {// ?android 3.0
                builder.setContentText(String.format(mContext.getString(R.string.sdk_download_progress_percent),
                        getDownloadingText(item.mTotalTotal, item.mTotalCurrent)));
            }
        }
        // ?()
        // if (item.mStatus == Downloads.STATUS_PENDING || item.mStatus ==
        // Downloads.STATUS_RUNNING) {
        // Intent pauseIt = new
        // Intent(ZMDownloadReceiver.DOWNLOADRECEIVER_PAUSE);
        // pauseIt.setPackage(mContext.getPackageName());
        // Bundle bundle = new Bundle();
        // bundle.putLong(ZMDownloadReceiver.INTENT_DOWNLOAD_ID, item.mId);
        // bundle.putInt(ZMDownloadReceiver.INTENT_DOWNLOAD_STATUS,
        // item.mStatus);
        // pauseIt.putExtras(bundle);
        // builder.addAction(R.drawable.sdk_download_pause,
        // mContext.getString(R.string.zuimeia_sdk_download_notification_pause),
        // PendingIntent.getBroadcast(mContext, 0, pauseIt,
        // PendingIntent.FLAG_CANCEL_CURRENT));
        // }
        // ?
        if (item.mStatus != Downloads.STATUS_SUCCESS) {
            Intent cancelIt = new Intent(DownloadReceiver.DOWNLOAD_CANCEL);
            cancelIt.setPackage(mContext.getPackageName());
            Bundle bundle = new Bundle();
            bundle.putLong(DownloadReceiver.INTENT_DOWNLOAD_ID, item.mId);
            bundle.putInt(DownloadReceiver.INTENT_DOWNLOAD_STATUS, item.mStatus);
            cancelIt.putExtras(bundle);
            builder.addAction(R.drawable.sdk_download_download_cancel,
                    mContext.getString(R.string.sdk_download_notification_cancel),
                    PendingIntent.getBroadcast(mContext, 0, cancelIt, PendingIntent.FLAG_CANCEL_CURRENT));
        }

        Intent intent = new Intent(Constants.ACTION_LIST);
        intent.setClassName(mContext, DownloadReceiver.class.getName());
        intent.setData(ContentUris.withAppendedId(Downloads.getAllDownloadsContentURI(mContext), item.mId));
        intent.putExtra("multiple", item.mTitleCount > 1);

        builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));

        mSystemFacade.postNotification(item.mId, builder.build());
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java

private void saveAlarmPoint() {
    Location location = zone.getLocation();
    if (location == null) {
        Toast.makeText(this, "No location. Try again...", Toast.LENGTH_LONG).show();
        return;//  www . j  a va 2s  .co  m
    }

    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses;
    String address;
    try {
        addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        address = addresses.get(0).getAddressLine(0) + ", " + addresses.get(0).getLocality();
    } catch (IOException e) {
        //         Log.e("Geoffrey", "Geocoding error...");
        e.printStackTrace();
        address = "Unknown address";
    }

    saveCoordinatesInPreferences((float) location.getLatitude(), (float) location.getLongitude(),
            zone.getRadius(), address);
    locationManager.removeUpdates(this);

    Intent bdintent = new Intent();
    bdintent.setClassName("com.geoffreybuttercrumbs.arewethereyet",
            "com.geoffreybuttercrumbs.arewethereyet.AlarmService");
    bdintent.putExtra(RADIUS, zone.getRadius());
    bdintent.putExtra(LOC, location);
    bdintent.putExtra(TONE, uri);
    bdintent.putExtra(ADDRESS, address);
    startService(bdintent);

    Toast.makeText(this, "Saving Alarm...", Toast.LENGTH_LONG).show();

    finish();
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java

public static Intent getLaunchIntent(Context context, SignedObj obj) {
    JSONObject content = obj.getJson();/* w ww  .  j ava 2  s.c  o m*/

    if (DBG)
        Log.d(TAG, "Getting launch intent for " + content);
    Uri appFeed;
    if (content.has(DbObject.CHILD_FEED_NAME)) {
        Log.d(TAG, "using child feed");
        appFeed = Feed.uriForName(content.optString(DbObject.CHILD_FEED_NAME));
    } else {
        Log.d(TAG, "using obj feed");
        appFeed = Feed.uriForName(content.optString(DbObjects.FEED_NAME));
    }
    String arg = content.optString(ARG);
    String state = content.optString(STATE);
    String appId = obj.getAppId();
    // TODO: Hack for deprecated launch method
    if (appId.equals(DungBeetleContentProvider.SUPER_APP_ID)) {
        appId = content.optString(PACKAGE_NAME);
    }
    if (DBG)
        Log.d(TAG, "Preparing launch of " + appId + " on " + appFeed);

    Intent launch = new Intent();
    if (content.has(AppReferenceObj.OBJ_INTENT_ACTION)) {
        launch.setAction(content.optString(AppReferenceObj.OBJ_INTENT_ACTION));
    } else {
        launch.setAction(Intent.ACTION_MAIN);
    }
    if (state != null) {
        launch.putExtra("mobisocial.db.STATE", state);
    }
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra(AppState.EXTRA_FEED_URI, appFeed);

    // TODO: hack until this obj is available in 'related' query.
    launch.putExtra("obj", content.toString());
    // TODO: this is better.
    launch.putExtra(Musubi.EXTRA_OBJ_HASH, obj.getHash());

    if (arg != null) {
        launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg);
    }
    // TODO: optimize!
    List<ResolveInfo> resolved = context.getPackageManager().queryIntentActivities(launch, 0);
    for (ResolveInfo r : resolved) {
        ActivityInfo activity = r.activityInfo;
        if (activity.packageName.equals(appId)) {
            launch.setClassName(activity.packageName, activity.name);
            launch.putExtra("mobisocial.db.PACKAGE", activity.packageName);
            return launch;
        }
    }

    Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appId));
    return market;
}

From source file:com.android.tv.settings.about.AboutFragment.java

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()) {
    case KEY_FIRMWARE_VERSION:
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            if (mUm.hasUserRestriction(UserManager.DISALLOW_FUN)) {
                Log.d(TAG, "Sorry, no fun for you!");
                return false;
            }//  w  ww. j  av a 2s  .c o m

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("android", com.android.internal.app.PlatLogoActivity.class.getName());
            try {
                startActivity(intent);
            } catch (Exception e) {
                Log.e(TAG, "Unable to start activity " + intent.toString());
            }
        }
        break;
    case KEY_BUILD_NUMBER:
        // Don't enable developer options for secondary users.
        if (!mUm.isAdminUser())
            return true;

        if (mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES))
            return true;

        if (mDevHitCountdown > 0) {
            mDevHitCountdown--;
            if (mDevHitCountdown == 0) {
                Settings.Global.putInt(getActivity().getContentResolver(),
                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on, Toast.LENGTH_LONG);
                mDevHitToast.show();
                // This is good time to index the Developer Options
                //                    Index.getInstance(
                //                            getActivity().getApplicationContext()).updateFromClassNameResource(
                //                            DevelopmentSettings.class.getName(), true, true);

            } else if (mDevHitCountdown > 0 && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER - 2)) {
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
                        R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown), Toast.LENGTH_SHORT);
                mDevHitToast.show();
            }
        } else if (mDevHitCountdown < 0) {
            if (mDevHitToast != null) {
                mDevHitToast.cancel();
            }
            mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already, Toast.LENGTH_LONG);
            mDevHitToast.show();
        }
        break;
    case KEY_DEVICE_FEEDBACK:
        sendFeedback();
        break;
    case KEY_SYSTEM_UPDATE_SETTINGS:
        CarrierConfigManager configManager = (CarrierConfigManager) getActivity()
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
        PersistableBundle b = configManager.getConfig();
        if (b != null && b.getBoolean(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_BOOL)) {
            ciActionOnSysUpdate(b);
        }
        break;
    }
    return super.onPreferenceTreeClick(preference);
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);/*from   w w  w. j  a  va 2s . co  m*/

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}

From source file:com.doplgangr.secrecy.views.FileViewer.java

private Intent generateCustomChooserIntent(Intent prototype, ArrayList<Uri> uris) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>();
    Intent chooserIntent;// ww w . j a va 2 s .  c o  m

    Intent dummy = new Intent(prototype.getAction());
    dummy.setType(prototype.getType());
    List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(dummy, 0);

    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            if (resolveInfo.activityInfo == null
                    || resolveInfo.activityInfo.packageName.equalsIgnoreCase("com.doplgangr.secrecy"))
                continue;

            HashMap<String, String> info = new HashMap<String, String>();
            info.put("packageName", resolveInfo.activityInfo.packageName);
            info.put("className", resolveInfo.activityInfo.name);
            info.put("simpleName",
                    String.valueOf(resolveInfo.activityInfo.loadLabel(context.getPackageManager())));
            intentMetaInfo.add(info);
            for (Uri uri : uris)
                context.grantUriPermission(resolveInfo.activityInfo.packageName, uri,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

        if (!intentMetaInfo.isEmpty()) {
            // sorting for nice readability
            Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() {
                @Override
                public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
                    return map.get("simpleName").compareTo(map2.get("simpleName"));
                }
            });

            // create the custom intent list
            for (HashMap<String, String> metaInfo : intentMetaInfo) {
                Intent targetedShareIntent = (Intent) prototype.clone();
                targetedShareIntent.setPackage(metaInfo.get("packageName"));
                targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));
                targetedShareIntents.add(targetedShareIntent);
            }
            chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1),
                    CustomApp.context.getString(R.string.Dialog__send_file));
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
            return chooserIntent;
        }
    }

    return new Intent(Intent.ACTION_SEND); //Unable to do anything. Duh.
}