android.content.Intent#getDataString ( )源码实例Demo

下面列出了android.content.Intent#getDataString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: shinny-futures-android   文件: FeedBackActivity.java
@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;
}
 
源代码2 项目: Lucid-Browser   文件: MainActivity.java
/**
 * 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());
       			}
       			
       		}
       }
}
 
源代码3 项目: 365browser   文件: IntentHandler.java
/**
 * 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;
}
 
源代码4 项目: Dainty   文件: MainActivity.java
@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);
                }
        }
}
 
源代码5 项目: TelePlus-Android   文件: CustomTabsCopyReceiver.java
@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();
    }
}
 
源代码6 项目: FreezeYou   文件: UninstallReceiver.java
@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);
            }
        }
    }
}
 
源代码7 项目: io2015-codelabs   文件: RecipeActivity.java
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);
    }
}
 
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));
        }
    }
}
 
源代码9 项目: TvLauncher   文件: AppOperationReceiver.java
@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);

        }

    }
}
 
源代码10 项目: Slide   文件: CheckInstall.java
@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());
    }
}
 
源代码11 项目: Telegram   文件: CustomTabsCopyReceiver.java
@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();
    }
}
 
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
源代码13 项目: fdroidclient   文件: SwapSuccessView.java
@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!");
    }
}
 
源代码14 项目: letv   文件: TopRecommendFragment.java
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;
        }
    }
}
 
源代码15 项目: Os-FileUp   文件: MainActivity.java
@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;
        }
    }
}
 
源代码16 项目: DeviceConnect-Android   文件: WebViewActivity.java
@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);
    }
}
 
源代码17 项目: android-chromium   文件: AwShellActivity.java
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
源代码18 项目: edslite   文件: MediaMountedReceiver.java
@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;
	}
}
 
源代码19 项目: android-chromium   文件: ContentShellActivity.java
private static String getUrlFromIntent(Intent intent) {
    return intent != null ? intent.getDataString() : null;
}
 
源代码20 项目: RedReader   文件: CommentListingActivity.java
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!");
		}
	}
 
 方法所在类
 同类方法