Java Code Examples for android.content.Intent#toString()

The following examples show how to use android.content.Intent#toString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: BlackList   File: SMSProcessService.java    License: Apache License 2.0 6 votes vote down vote up
private Map<String, String> extractMessageData(@Nullable Intent intent) throws IllegalArgumentException {
    Map<String, String> data = new HashMap<>();
    if (intent != null) {
        String[] keys = intent.getStringArrayExtra(KEYS);
        String[] values = intent.getStringArrayExtra(VALUES);
        if (keys != null && values != null && keys.length == values.length) {
            for (int i = 0; i < keys.length; i++) {
                data.put(keys[i], values[i]);
            }
        }
    }

    if (data.isEmpty()) {
        String intentString = (intent == null ? "null" : intent.toString());
        throw new IllegalArgumentException("Message intent data is illegal: " + intentString);
    }

    return data;
}
 
Example 2
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    if (badgeCount == 0) {
        badgeCount = -1;
    }
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_BADGE_UPGRADENUMBER, badgeCount);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        int version = getSupportVersion();
        if (version == 6) {
            try {
                Bundle extras = new Bundle();
                extras.putInt(INTENT_EXTRA_BADGEUPGRADE_COUNT, badgeCount);
                context.getContentResolver().call(Uri.parse(PROVIDER_CONTENT_URI), "setAppBadgeCount", null, extras);
            } catch (Throwable th) {
                throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
            }
        }
    }
}
 
Example 3
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    try {
        Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
        Object miuiNotification = miuiNotificationClass.newInstance();
        Field field = miuiNotification.getClass().getDeclaredField("messageCount");
        field.setAccessible(true);
        field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount));
    } catch (Exception e) {
        Intent localIntent = new Intent(
                INTENT_ACTION);
        localIntent.putExtra(EXTRA_UPDATE_APP_COMPONENT_NAME, componentName.getPackageName() + "/" + componentName.getClassName());
        localIntent.putExtra(EXTRA_UPDATE_APP_MSG_TEXT, String.valueOf(badgeCount == 0 ? "" : badgeCount));
        if (BroadcastHelper.canResolveBroadcast(context, localIntent)) {
            context.sendBroadcast(localIntent);
        } else {
            throw new ShortcutBadgeException("unable to resolve intent: " + localIntent.toString());
        }
    }
}
 
Example 4
Source Project: AndroidBase   File: NewHtcHomeBadger.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {

    Intent intent1 = new Intent(INTENT_SET_NOTIFICATION);
    intent1.putExtra(EXTRA_COMPONENT, componentName.flattenToShortString());
    intent1.putExtra(EXTRA_COUNT, badgeCount);

    Intent intent = new Intent(INTENT_UPDATE_SHORTCUT);
    intent.putExtra(PACKAGENAME, componentName.getPackageName());
    intent.putExtra(COUNT, badgeCount);

    if(BroadcastHelper.canResolveBroadcast(context, intent1) || BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent1);
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 5
Source Project: AndroidBase   File: OPPOHomeBader.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    if (badgeCount == 0) {
        badgeCount = -1;
    }
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_BADGE_UPGRADENUMBER, badgeCount);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        int version = getSupportVersion();
        if (version == 6) {
            try {
                Bundle extras = new Bundle();
                extras.putInt(INTENT_EXTRA_BADGEUPGRADE_COUNT, badgeCount);
                context.getContentResolver().call(Uri.parse(PROVIDER_CONTENT_URI), "setAppBadgeCount", null, extras);
            } catch (Throwable th) {
                throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
            }
        }
    }
}
 
Example 6
Source Project: AndroidBase   File: XiaomiHomeBadger.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    try {
        Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
        Object miuiNotification = miuiNotificationClass.newInstance();
        Field field = miuiNotification.getClass().getDeclaredField("messageCount");
        field.setAccessible(true);
        field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount));
    } catch (Exception e) {
        Intent localIntent = new Intent(
                INTENT_ACTION);
        localIntent.putExtra(EXTRA_UPDATE_APP_COMPONENT_NAME, componentName.getPackageName() + "/" + componentName.getClassName());
        localIntent.putExtra(EXTRA_UPDATE_APP_MSG_TEXT, String.valueOf(badgeCount == 0 ? "" : badgeCount));
        if (BroadcastHelper.canResolveBroadcast(context, localIntent)) {
            context.sendBroadcast(localIntent);
        } else {
            throw new ShortcutBadgeException("unable to resolve intent: " + localIntent.toString());
        }
    }
}
 
Example 7
Source Project: AndroidBase   File: AdwHomeBadger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {

    Intent intent = new Intent(INTENT_UPDATE_COUNTER);
    intent.putExtra(PACKAGENAME, componentName.getPackageName());
    intent.putExtra(CLASSNAME, componentName.getClassName());
    intent.putExtra(COUNT, badgeCount);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 8
private void sendToPlayStore(){
    final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
    final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

    if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0)
    {
        startActivity(rateAppIntent);
        rateAppIntent.toString();
    }
    else
    {
        /* handle your error case: the device has no way to handle market urls */
    }
}
 
Example 9
Source Project: BadgeForAppIcon   File: SamsungModelImpl.java    License: MIT License 5 votes vote down vote up
@Override
public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception {
    Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
    intent.putExtra("badge_count", count);
    intent.putExtra("badge_count_package_name", context.getPackageName());
    intent.putExtra("badge_count_class_name", Utils.getInstance().getLaunchIntentForPackage(context));

    if (Utils.getInstance().canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new Exception(UNABLE_TO_RESOLVE_INTENT_ERROR_ + intent.toString());
    }
    return notification;
}
 
Example 10
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {

    Intent intent = new Intent(INTENT_UPDATE_COUNTER);
    intent.putExtra(PACKAGENAME, componentName.getPackageName());
    intent.putExtra(COUNT, badgeCount);
    intent.putExtra(CLASS, componentName.getClassName());
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 11
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 12
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    if(BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 13
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    intent.putExtra("badge_vip_count", 0);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 14
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {

    Intent intent = new Intent(INTENT_UPDATE_COUNTER);
    intent.putExtra(PACKAGENAME, componentName.getPackageName());
    intent.putExtra(CLASSNAME, componentName.getClassName());
    intent.putExtra(COUNT, badgeCount);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 15
Source Project: AndroidBase   File: AsusHomeLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    intent.putExtra("badge_vip_count", 0);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 16
Source Project: AndroidBase   File: DefaultBadger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 17
Source Project: AndroidBase   File: VIVOHomeBader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    if (badgeCount == 0) {
        badgeCount = -1;
    }
    Intent intent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
    intent.putExtra("packageName", componentName.getPackageName());
    intent.putExtra("className", componentName.getClassName());
    intent.putExtra("notificationNum", badgeCount);
    if (BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 18
Source Project: AndroidBase   File: LGHomeBadger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
    Intent intent = new Intent(INTENT_ACTION);
    intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
    intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
    intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
    if(BroadcastHelper.canResolveBroadcast(context, intent)) {
        context.sendBroadcast(intent);
    } else {
        throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
    }
}
 
Example 19
private String getIntentString(Intent intent) {
    return intent != null ? intent.toString() : "(no intent)";
}
 
Example 20
Source Project: Yahala-Messenger   File: ChatActivity.java    License: MIT License 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 0) {
            Utilities.addMediaToGallery(currentPicturePath);
            processSendingPhoto(currentPicturePath, null);
            currentPicturePath = null;
        } else if (requestCode == 1) {
            if (data == null) {
                return;
            }
            processSendingPhoto(null, data.getData());
        } else if (requestCode == 2) {
            String videoPath = null;
            if (data != null) {
                Uri uri = data.getData();
                boolean fromCamera = false;
                if (uri != null && uri.getScheme() != null) {
                    fromCamera = uri.getScheme().contains("file");
                } else if (uri == null) {
                    fromCamera = true;
                }
                if (fromCamera) {
                    if (uri != null) {
                        videoPath = uri.getPath();
                    } else {
                        videoPath = currentPicturePath;
                    }
                    Utilities.addMediaToGallery(currentPicturePath);
                    currentPicturePath = null;
                } else {
                    try {
                        videoPath = Utilities.getPath(uri);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
            if (videoPath == null && currentPicturePath != null) {
                File f = new File(currentPicturePath);
                if (f.exists()) {
                    videoPath = currentPicturePath;
                }
                currentPicturePath = null;
            }
           /* if(android.os.Build.VERSION.SDK_INT >= 10) {
               Bundle args = new Bundle();
                args.putString("videoPath", videoPath);
                VideoEditorActivity fragment = new VideoEditorActivity();
                fragment.setArguments(args);
                fragment.setDelegate(this);
                ((LaunchActivity)parentActivity).presentFragment(fragment,"Video Editor Activity",false);
            } else {*/
            processSendingVideo(videoPath);
            // }

        } else if (requestCode == 21) {
            if (data == null || data.getData() == null) {
                showAttachmentError();
                return;
            }
            String tempPath = Utilities.getPath(data.getData());
            String originalPath = tempPath;
            if (tempPath == null) {
                originalPath = data.toString();
                tempPath = MediaController.copyDocumentToCache(data.getData(), "file");
            }
            if (tempPath == null) {
                showAttachmentError();
                return;
            }
            processSendingDocument(tempPath, originalPath);
        }
    }
}