Example usage for android.content Intent getDataString

List of usage examples for android.content Intent getDataString

Introduction

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

Prototype

public @Nullable String getDataString() 

Source Link

Document

The same as #getData() , but returns the URI as an encoded String.

Usage

From source file:com.eternizedlab.lunarcalendar.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default_title);
    }//from  w  w  w. j  av a  2  s . c o m

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default_title);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:io.teak.sdk.Session.java

/**
 * Process an Intent and assign new values for launching from a deep link or Teak notification.
 * <p/>//from   ww w . j  av  a 2  s. co m
 * If currentSession was launched via a deep link or notification, and the incoming intent has
 * a new (non null/empty) value. Create a new Session, cloning state from the old one.
 *
 * @param intent Incoming Intent to process.
 */
public static void processIntent(Intent intent, @NonNull AppConfiguration appConfiguration,
        @NonNull DeviceConfiguration deviceConfiguration) {
    if (intent == null)
        return;

    synchronized (currentSessionMutex) {
        // Call getCurrentSession() so the null || Expired logic stays in one place
        getCurrentSession(appConfiguration, deviceConfiguration);

        // Check for launch via deep link
        String intentDataString = intent.getDataString();
        String launchedFromDeepLink = null;
        if (intentDataString != null && !intentDataString.isEmpty()) {
            launchedFromDeepLink = intentDataString;
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Launch from deep link: " + launchedFromDeepLink);
            }
        }

        // Check for launch via notification
        Bundle bundle = intent.getExtras();
        String launchedFromTeakNotifId = null;
        if (bundle != null) {
            String teakNotifId = bundle.getString("teakNotifId");
            if (teakNotifId != null && !teakNotifId.isEmpty()) {
                launchedFromTeakNotifId = teakNotifId;
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Launch from Teak notification: " + launchedFromTeakNotifId);
                }
            }
        }

        // If the current session has a launch from deep link/notification, and there is a new
        // deep link/notification, it's a new session
        if (stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromDeepLink, launchedFromDeepLink)
                || stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromTeakNotifId,
                        launchedFromTeakNotifId)) {
            Session oldSession = currentSession;
            currentSession = new Session(oldSession.appConfiguration, oldSession.deviceConfiguration);
            currentSession.userId = oldSession.userId;
            currentSession.attributionChain.addAll(oldSession.attributionChain);

            oldSession.setState(State.Expiring);
            oldSession.setState(State.Expired);
        }

        // Assign attribution
        if (launchedFromDeepLink != null && !launchedFromDeepLink.isEmpty()) {
            currentSession.launchedFromDeepLink = launchedFromDeepLink;
            currentSession.attributionChain.add(launchedFromDeepLink);
        } else if (launchedFromTeakNotifId != null && !launchedFromTeakNotifId.isEmpty()) {
            currentSession.launchedFromTeakNotifId = launchedFromTeakNotifId;
            currentSession.attributionChain.add(launchedFromTeakNotifId);
        }
    }
}

From source file:com.noshufou.android.su.InstallReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    String packageName = intent.getDataString().split(":")[1];
    PackageInfo packageInfo = null;//  w w w.j a v  a  2 s.  co  m

    try {
        packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
    } catch (NameNotFoundException e) {
        // This won't happen, but if it does, we don't continue
        Log.e(TAG, "PackageManager divided by zero...", e);
        return;
    }

    if (Util.isPackageMalicious(context, packageInfo) != 0) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent notificationIntent = new Intent(Intent.ACTION_DELETE, intent.getData());
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.stat_su)
                .setTicker(context.getText(R.string.malicious_app_notification_ticker))
                .setWhen(System.currentTimeMillis()).setContentTitle(context.getText(R.string.app_name))
                .setContentText(context.getString(R.string.malicious_app_notification_text,
                        pm.getApplicationLabel(packageInfo.applicationInfo)))
                .setContentIntent(contentIntent).setAutoCancel(true).getNotification();
        nm.notify(0, notification);
    }
}

From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;//from  w w  w  .j  av a  2  s  .c  om
    }

    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Ignore application updates
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        if (!replacing) {
            // Update the Firewall if necessary
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
            Api.applicationRemoved(context, uid);
            Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context);
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                final PackageManager pkgmanager = context.getPackageManager();
                String label = null;
                try {
                    label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0))
                            .toString();
                } catch (NameNotFoundException e) {
                }
                if (PackageManager.PERMISSION_GRANTED == pkgmanager
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, label);
                }
            }
        }
    }
}

From source file:dev.ukanth.ufirewall.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;/*from w  w  w .jav  a2 s  . co m*/
    }

    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Ignore application updates
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        if (!replacing) {
            // Update the Firewall if necessary
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
            Api.applicationRemoved(context, uid);
            /*Api.applicationRemoved(context,
             inputUri.getSchemeSpecificPart());*/
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                if (PackageManager.PERMISSION_GRANTED == context.getPackageManager()
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, added_package);
                }
            }
        }

    }
}

From source file:com.futureplatforms.kirin.test.LocalNotificationBackendTest.java

public void testCreatePendingIntent() throws Exception {
    Intent intent = mBackend.createIntentForSchedule("1234");
    assertNotNull(intent);/* ww  w  . ja v a2  s. c  o  m*/

    assertEquals("kirin://com.futureplatforms/localNotifications/1234", intent.getDataString());

}

From source file:sample.multithreading.NetworkDownloadService.java

@Override
protected void onHandleIntent(Intent paramIntent) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    String str = paramIntent.getDataString();
    URL localURL;/*from  w  w w.j  a  v  a 2  s. c om*/
    try {
        localURL = new URL(str);
        URLConnection localURLConnection = localURL.openConnection();
        if ((localURLConnection instanceof HttpURLConnection)) {
            broadcastIntentWithState(STATE_ACTION_STARTED);
            HttpURLConnection localHttpURLConnection = (HttpURLConnection) localURLConnection;
            localHttpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
            broadcastIntentWithState(STATE_ACTION_CONNECTING);
            localHttpURLConnection.getResponseCode();
            broadcastIntentWithState(STATE_ACTION_PARSING);
            PicasaPullParser localPicasaPullParser = new PicasaPullParser();
            localPicasaPullParser.parseXml(localURLConnection.getInputStream(), this);
            broadcastIntentWithState(STATE_ACTION_WRITING);
            Vector<ContentValues> cvv = localPicasaPullParser.getImages();
            int size = cvv.size();
            ContentValues[] cvArray = new ContentValues[size];
            cvArray = cvv.toArray(cvArray);
            getContentResolver().bulkInsert(PicasaContentDB.getUriByType(this, PicasaContentDB.METADATA_QUERY),
                    cvArray);
            broadcastIntentWithState(STATE_ACTION_COMPLETE);
        }
    } catch (MalformedURLException localMalformedURLException) {
        localMalformedURLException.printStackTrace();
    } catch (IOException localIOException) {
        localIOException.printStackTrace();
    } catch (XmlPullParserException localXmlPullParserException) {
        localXmlPullParserException.printStackTrace();
    }
    Log.d(LOG_TAG, "onHandleIntent Complete");
}

From source file:org.dmfs.oauth2.android.fragment.OAuth2GrantProxyFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        try {//from   ww w .ja v a  2s.  c o m
            sendState(mGrant.withRedirect(new LazyUri(new Precoded(data.getDataString()))).state());
        } catch (ProtocolError e) {
            sendState(new ErrorOAuth2GrantState(e));
        } catch (ProtocolException e) {
            sendState(new ExceptionOAuth2GrantState(e));
        }
    } else {
        sendState(
                new ErrorOAuth2GrantState(new AuthorizationCancelledError("Authorization cancelled by user.")));
    }
    getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
}

From source file:com.chess.genesis.activity.GameListLocalFrag.java

public void recieveGame(final Intent data) {
    try {//from w  ww.ja va2 s .c o  m
        if (data == null || data.getDataString() == null) {
            Toast.makeText(act, "Intent has no data", Toast.LENGTH_LONG).show();
            return;
        }

        final String str = FileUtils.readFile(data.getDataString());
        final JSONObject json = (JSONObject) new JSONTokener(str).nextValue();
        final Bundle game = GameParser.parse(json);
        final GameDataDB db = new GameDataDB(act);

        db.addLocalGame(game);
        db.close();
        gamelist_adapter.update();
    } catch (final FileNotFoundException e) {
        Toast.makeText(act, "File Not Found", Toast.LENGTH_LONG).show();
    } catch (final IOException e) {
        Toast.makeText(act, "Error Reading File", Toast.LENGTH_LONG).show();
    } catch (final JSONException e) {
        Toast.makeText(act, "Not A Game Data File", Toast.LENGTH_LONG).show();
    } catch (final ClassCastException e) {
        Toast.makeText(act, "Not A Game Data File", Toast.LENGTH_LONG).show();
    }
}

From source file:org.lol.reddit.activities.CommentListingActivity.java

public void onCreate(final Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    OptionsMenuUtility.fixActionBar(this, getString(R.string.app_name));

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);

    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    // TODO load from savedInstanceState

    final View layout = getLayoutInflater().inflate(R.layout.main_single);
    if (solidblack)
        layout.setBackgroundColor(Color.BLACK);
    setContentView(layout);/*from   w ww. j  a v  a 2s . c  o m*/

    RedditAccountManager.getInstance(this).addUpdateListener(this);

    if (getIntent() != null) {

        final Intent intent = getIntent();

        final String url = intent.getDataString();
        controller = new CommentListingController(RedditURLParser.parseProbableCommentListing(Uri.parse(url)),
                this);

        doRefresh(RefreshableFragment.COMMENTS, false);

    } else {
        throw new RuntimeException("Nothing to show! (should load from bundle)"); // TODO
    }
}