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

The following examples show how to use android.content.Intent#getDataString() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Lucid-Browser   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * When an app chooses to open a link with this browser (and the browser is already open), onNewIntent is called
 * @param intent provided by different app/activity
 */
@Override
   protected void onNewIntent(Intent intent) {
       super.onNewIntent(intent);
       Log.d("LB", "onNewIntent");
       if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
               Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
       	drawerLayout.closeDrawers();
       }
       
       if (intent.getAction()!=null && (intent.getAction().equals(Intent.ACTION_WEB_SEARCH) ||intent.getAction().equals(Intent.ACTION_VIEW))){
       		if (intent.getDataString()!=null){
       			int tabNumber = intent.getIntExtra("tabNumber", -1); //used if intent is coming from Lucid Browser
       			
       			if (tabNumber!=-1 && tabNumber < webWindows.size()){
       				webWindows.get(tabNumber).loadUrl(intent.getDataString());
       			}else
       				tabNumber=-1;
       				
       			if (tabNumber==-1){
    	    		openURLInNewTab(intent.getDataString());
       			}
       			
       		}
       }
}
 
Example 2
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    if (requestCode != FILE_CHOOSER_RESULT_CODE || mUploadMessageAboveL == null)
        return;
    Uri[] results = null;
    if (resultCode == Activity.RESULT_OK) {
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null)
                results = new Uri[]{Uri.parse(dataString)};
        }
    }
    mUploadMessageAboveL.onReceiveValue(results);
    mUploadMessageAboveL = null;
}
 
Example 3
Source Project: 365browser   File: IntentHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the URL from the Intent, which may be in multiple locations.
 * @param intent Intent to examine.
 * @return URL from the Intent, or null if a valid URL couldn't be found.
 */
public static String getUrlFromIntent(Intent intent) {
    if (intent == null) return null;

    String url = getUrlFromVoiceSearchResult(intent);
    if (url == null) url = ActivityDelegate.getInitialUrlForDocument(intent);
    if (url == null) url = getUrlForCustomTab(intent);
    if (url == null) url = intent.getDataString();
    if (url == null) return null;

    url = url.trim();
    if (isGoogleChromeScheme(url)) {
        url = getUrlFromGoogleChromeSchemeUrl(url);
    }
    return TextUtils.isEmpty(url) ? null : url;
}
 
Example 4
Source Project: Dainty   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String action = intent.getAction();
    String url;
    if (action != null)
        switch (action) {
            case Intent.ACTION_VIEW:
            case "com.zbm.dainty.action.VIEW":
                url = intent.getDataString();
                if (url != null) {
                    Log.d("Main", "onNewIntent地址Path:" + url);
                    webView.loadUrl(url);
                    return;
                }
                break;
            default:
                url = intent.getStringExtra("shortcut_url");
                if (webView != null) {
                    webView.loadUrl(url);
                }
        }
}
 
Example 5
@Override
public void onReceive(Context context, Intent intent) {
    String url = intent.getDataString();
    if (url != null) {
        AndroidUtilities.addToClipboard(url);
        Toast.makeText(context, LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source Project: FreezeYou   File: UninstallReceiver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    if (intent == null) {
        return;
    }

    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(intent.getAction())) {
        String pkgName = intent.getDataString();
        if (pkgName != null) {
            pkgName = pkgName.replace("package:", "");
            if (ApplicationInfoUtils.getApplicationInfoFromPkgName(pkgName, context) == null) {
                removeFromOneKeyList(context, context.getString(R.string.sAutoFreezeApplicationList), pkgName);
                removeFromOneKeyList(context, context.getString(R.string.sOneKeyUFApplicationList), pkgName);
                removeFromOneKeyList(context, context.getString(R.string.sFreezeOnceQuit), pkgName);
                //清理被卸载应用程序的图标数据
                File file = new File(context.getFilesDir() + "/icon/" + pkgName + ".png");
                if (file.exists() && file.isFile()) {
                    file.delete();
                }
                File file2 = new File(context.getCacheDir() + "/icon/" + pkgName + ".png");
                if (file2.exists() && file2.isFile()) {
                    file2.delete();
                }
                //清理被卸载应用程序的名称
                context.getSharedPreferences("NameOfPackages", Context.MODE_PRIVATE)
                        .edit().remove(pkgName).apply();
                //清理可能存在的通知栏提示重新显示数据
                deleteNotification(context, pkgName);
            }
        }
    }
}
 
Example 7
Source Project: io2015-codelabs   File: RecipeActivity.java    License: Apache License 2.0 5 votes vote down vote up
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        String recipeId = data.substring(data.lastIndexOf("/") + 1);
        Uri contentUri = RecipeContentProvider.CONTENT_URI.buildUpon()
                .appendPath(recipeId).build();
        showRecipe(contentUri);
    }
}
 
Example 8
private void fileChoosed(int resultCode, Intent data) {
    if (data == null) {
        return;
    }
    if (resultCode == RESULT_OK) {
        String path = data.getDataString();
        Log.d(TAG, "path:" + path);
        if (isImageFile(path)) {
            ((ImageView) findViewById(R.id.image)).setImageURI(Uri
                    .parse(path));
        }
    }
}
 
Example 9
Source Project: TvLauncher   File: AppOperationReceiver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "============匹配广播,执行相应操作===================");
    if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
        Log.d(TAG, "============接收应用卸载广播===================");
        MainActivity mainActivity = getOwner();
        String packageName = intent.getDataString();
        if (!packageName.equals("package:" + context.getPackageName())) {

            mainActivity.getAppPage().refresh(true);

        }

    }
}
 
Example 10
Source Project: Slide   File: CheckInstall.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String packageName = intent.getDataString();
    if (packageName.equals(context.getString(R.string.youtube_plugin_package))
            || packageName.equals(context.getString(R.string.ui_unlock_package))) {
        ProcessPhoenix.triggerRebirth(context.getApplicationContext());
    }
}
 
Example 11
@Override
public void onReceive(Context context, Intent intent) {
    String url = intent.getDataString();
    if (url != null) {
        AndroidUtilities.addToClipboard(url);
        Toast.makeText(context, LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
    }
}
 
Example 12
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
Example 13
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Downloader.ACTION_STARTED:
            resetView();
            break;
        case Downloader.ACTION_PROGRESS:
            if (progressView.getVisibility() != View.VISIBLE) {
                showProgress();
            }
            long read = intent.getLongExtra(Downloader.EXTRA_BYTES_READ, 0);
            long total = intent.getLongExtra(Downloader.EXTRA_TOTAL_BYTES, 0);
            if (total > 0) {
                progressView.setIndeterminate(false);
                progressView.setMax(100);
                progressView.setProgress(Utils.getPercent(read, total));
            } else {
                progressView.setIndeterminate(true);
            }
            break;
        case Downloader.ACTION_COMPLETE:
            localBroadcastManager.unregisterReceiver(this);
            resetView();
            statusInstalled.setText(R.string.installing);
            statusInstalled.setVisibility(View.VISIBLE);
            btnInstall.setVisibility(View.GONE);
            break;
        case Downloader.ACTION_INTERRUPTED:
            localBroadcastManager.unregisterReceiver(this);
            if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) {
                String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE)
                        + " " + intent.getDataString();
                Toast.makeText(context, R.string.download_error, Toast.LENGTH_SHORT).show();
                Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
            } else { // user canceled
                Toast.makeText(context, R.string.details_notinstalled, Toast.LENGTH_LONG).show();
            }
            resetView();
            break;
        default:
            throw new RuntimeException("intent action not handled!");
    }
}
 
Example 14
Source Project: letv   File: TopRecommendFragment.java    License: Apache License 2.0 4 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    RecommenApp recommenApp;
    boolean z = true;
    if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
        String packageName = intent.getDataString();
        LogInfo.log("HYX", "安装了:" + packageName + "包名的程序");
        String substring = packageName.substring(8);
        LogInfo.log("HYX", "包名:" + substring);
        this.this$0.infodatas.add(substring);
        boolean z2;
        switch (TopRecommendFragment.selectedType) {
            case 0:
                LogInfo.log("HYX", "当前为:0");
                this.this$0.listAdapter1.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(0);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(0)).isFlag()) {
                    z2 = false;
                } else {
                    z2 = true;
                }
                recommenApp.setFlag(z2);
                this.this$0.listAdapter1.notifyDataSetChanged();
                break;
            case 1:
                LogInfo.log("HYX", "当前为:1");
                this.this$0.listAdapter2.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(0);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(0)).isFlag()) {
                    z2 = false;
                } else {
                    z2 = true;
                }
                recommenApp.setFlag(z2);
                this.this$0.listAdapter2.notifyDataSetChanged();
                break;
            case 2:
                LogInfo.log("HYX", "当前为:2");
                this.this$0.listAdapter3.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(0);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(0)).isFlag()) {
                    z2 = false;
                } else {
                    z2 = true;
                }
                recommenApp.setFlag(z2);
                this.this$0.listAdapter3.notifyDataSetChanged();
                break;
        }
    }
    if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
        packageName = intent.getDataString();
        LogInfo.log("HYX", "卸载了:" + packageName + "包名的程序");
        substring = packageName.substring(8);
        LogInfo.log("HYX", "卸载的包名:" + substring);
        this.this$0.infodatas.remove(substring);
        switch (TopRecommendFragment.selectedType) {
            case 0:
                LogInfo.log("HYX", "当前为:0");
                this.this$0.listAdapter1.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(1);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(1)).isFlag()) {
                    z = false;
                }
                recommenApp.setFlag(z);
                this.this$0.listAdapter1.notifyDataSetChanged();
                return;
            case 1:
                LogInfo.log("HYX", "当前为:1");
                this.this$0.listAdapter2.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(1);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(1)).isFlag()) {
                    z = false;
                }
                recommenApp.setFlag(z);
                this.this$0.listAdapter2.notifyDataSetChanged();
                return;
            case 2:
                LogInfo.log("HYX", "当前为:2");
                this.this$0.listAdapter3.setdatas(this.this$0.infodatas);
                recommenApp = (RecommenApp) this.this$0.mRecommData.getAppList().get(1);
                if (((RecommenApp) this.this$0.mRecommData.getAppList().get(1)).isFlag()) {
                    z = false;
                }
                recommenApp.setFlag(z);
                this.this$0.listAdapter3.notifyDataSetChanged();
                return;
            default:
                return;
        }
    }
}
 
Example 15
Source Project: Os-FileUp   File: MainActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    super.onActivityResult(requestCode, resultCode, intent);
    if(Build.VERSION.SDK_INT >= 21){
        Uri[] results = null;

        /*-- if file request cancelled; exited camera. we need to send null value to make future attempts workable --*/
        if (resultCode == Activity.RESULT_CANCELED) {
            if (requestCode == file_req_code) {
                file_path.onReceiveValue(null);
                return;
            }
        }

        /*-- continue if response is positive --*/
        if(resultCode== Activity.RESULT_OK){
            if(requestCode == file_req_code){
                if(null == file_path){
                    return;
                }

                ClipData clipData;
                String stringData;
                try {
                    clipData = intent.getClipData();
                    stringData = intent.getDataString();
                }catch (Exception e){
                    clipData = null;
                    stringData = null;
                }

                if (clipData == null && stringData == null && cam_file_data != null) {
                    results = new Uri[]{Uri.parse(cam_file_data)};
                }else{
                    if (clipData != null) { // checking if multiple files selected or not
                        final int numSelectedFiles = clipData.getItemCount();
                        results = new Uri[numSelectedFiles];
                        for (int i = 0; i < clipData.getItemCount(); i++) {
                            results[i] = clipData.getItemAt(i).getUri();
                        }
                    } else {
                        results = new Uri[]{Uri.parse(stringData)};
                    }
                }
            }
        }
        file_path.onReceiveValue(results);
        file_path = null;
    }else{
        if(requestCode == file_req_code){
            if(null == file_data) return;
            Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
            file_data.onReceiveValue(result);
            file_data = null;
        }
    }
}
 
Example 16
Source Project: DeviceConnect-Android   File: WebViewActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == INPUT_FILE_REQUEST_CODE) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (mFilePathCallback == null) {
                super.onActivityResult(requestCode, resultCode, data);
                return;
            }

            Uri[] results = null;
            if (resultCode == RESULT_OK) {
                String dataString = data.getDataString();
                if (dataString != null) {
                    results = new Uri[] { Uri.parse(dataString) };
                }
            }

            mFilePathCallback.onReceiveValue(results);
            mFilePathCallback = null;
        } else {
            if (mUploadMessage == null) {
                super.onActivityResult(requestCode, resultCode, data);
                return;
            }

            Uri result = null;
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    result = data.getData();
                }
            }

            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
        }
    } else if(requestCode == REQUEST_CODE_FROM_JS) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            cursor.close();
        }

        String imgPath = getPath(selectedImage);

        BitmapFactory.Options options;
        options = new BitmapFactory.Options();
        options.inSampleSize = 3;
        Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options);

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] b = stream.toByteArray();
        String encodedString = Base64.encodeToString(b, Base64.DEFAULT);
        mWebView.loadUrl("javascript:chooseImgResult(" + encodedString + ")");
    } else {
        super.onActivityResult(requestCode,resultCode, data);
    }
}
 
Example 17
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
Example 18
@Override
public void onReceive(Context context, Intent intent) 
{
	Logger.debug("MediaMountedReceiver");
	LocationsManagerBase lm = _lm;
	if(lm == null)
		return;
	String mountPath = intent.getDataString();
       ExternalStorageLocation loc = mountPath != null ? new ExternalStorageLocation(context, "ext storage", mountPath, null) : null;
	try
	{
		Thread.sleep(3000);
	}
	catch (InterruptedException e)
	{
		e.printStackTrace();
	}
	switch (intent.getAction())
	{
		case UsbManager.ACTION_USB_DEVICE_ATTACHED:
			Logger.debug("ACTION_USB_DEVICE_ATTACHED");
			lm.updateDeviceLocations();
			LocationsManager.broadcastLocationAdded(context, loc);
			break;
		case Intent.ACTION_MEDIA_MOUNTED:
			Logger.debug("ACTION_MEDIA_MOUNTED");
			lm.updateDeviceLocations();
			LocationsManager.broadcastLocationAdded(context, loc);
			break;
		case Intent.ACTION_MEDIA_UNMOUNTED:
			Logger.debug("ACTION_MEDIA_UNMOUNTED");
			lm.updateDeviceLocations();
			LocationsManager.broadcastLocationRemoved(context, loc);
			break;
		case Intent.ACTION_MEDIA_REMOVED:
			Logger.debug("ACTION_MEDIA_REMOVED");
			lm.updateDeviceLocations();
			LocationsManager.broadcastLocationRemoved(context, loc);
			break;
		case UsbManager.ACTION_USB_DEVICE_DETACHED:
			Logger.debug("ACTION_USB_DEVICE_DETACHED");
			lm.updateDeviceLocations();
			LocationsManager.broadcastLocationRemoved(context, loc);
			break;
	}
}
 
Example 19
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
Example 20
public void onCreate(final Bundle savedInstanceState) {

		PrefsUtility.applyTheme(this);

		super.onCreate(savedInstanceState);

		setTitle(getString(R.string.app_name));

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

		if(getIntent() != null) {

			final Intent intent = getIntent();

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

			Bundle fragmentSavedInstanceState = null;

			if(savedInstanceState != null) {

				if(savedInstanceState.containsKey(SAVEDSTATE_SESSION)) {
					controller.setSession(UUID.fromString(savedInstanceState.getString(SAVEDSTATE_SESSION)));
				}

				if(savedInstanceState.containsKey(SAVEDSTATE_SORT)) {
					controller.setSort(PostCommentListingURL.Sort.valueOf(
							savedInstanceState.getString(SAVEDSTATE_SORT)));
				}

				if(savedInstanceState.containsKey(SAVEDSTATE_FRAGMENT)) {
					fragmentSavedInstanceState = savedInstanceState.getBundle(SAVEDSTATE_FRAGMENT);
				}
			}

			doRefresh(RefreshableFragment.COMMENTS, false, fragmentSavedInstanceState);

		} else {
			throw new RuntimeException("Nothing to show!");
		}
	}