下面列出了android.content.Intent#getData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_FOR_VIDEO_FILE && resultCode == RESULT_OK) {
if (data != null && data.getData() != null) {
// inputPath = data.getData().getPath();
// tv_input.setText(inputPath);
try {
inputPath = Util.getFilePath(this, data.getData());
tv_input.setText(inputPath);
} catch (URISyntaxException e) {
e.printStackTrace();
}
// inputPath = "/storage/emulated/0/DCIM/Camera/VID_20170522_172417.mp4"; // 图片文件路径
// tv_input.setText(inputPath);// /storage/emulated/0/DCIM/Camera/VID_20170522_172417.mp4
}
}
}
private boolean handleInstallRequest(Intent intent) {
IAppRequestListener listener = VirtualCore.get().getAppRequestListener();
if (listener != null) {
Uri packageUri = intent.getData();
if (SCHEME_FILE.equals(packageUri.getScheme())) {
File sourceFile = new File(packageUri.getPath());
try {
listener.onRequestInstall(IOHook.getRedirectedPath(sourceFile.getPath()));
return true;
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
return false;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null) {
return;
}
try {
ContentResolver resolver = this.getContentResolver();
Uri uri = data.getData();
Bitmap bmp = MediaStore.Images.Media.getBitmap(resolver, uri);
Bitmap image = cropImage(bmp);
ImageView img = (ImageView) findViewById(R.id.imageView);
List<DetectResult> result = detector.detect(image);
Bitmap toDraw = PhotoViewHelper.drawTextAndRect(image, result);
img.setImageBitmap(toDraw);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.speaker_activity);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
TextView txtOutput = (TextView) findViewById(R.id.txtOutput);
ImageView imgSpeaker = (ImageView) findViewById(R.id.imgSpeaker);
String speakerName = data.toString().substring(data.toString().lastIndexOf("=") + 1);
txtOutput.setText(speakerName);
if(speakerName.equalsIgnoreCase("pareshmayani")){
imgSpeaker.setImageResource(R.drawable.paresh_mayani);
}else if(speakerName.equalsIgnoreCase("chintanrathod")){
imgSpeaker.setImageResource(R.drawable.chintan_rathod);
}else if(speakerName.equalsIgnoreCase("utpalbetai")){
imgSpeaker.setImageResource(R.drawable.utpal_betai);
}else if(speakerName.equalsIgnoreCase("dhrumilshah")){
imgSpeaker.setImageResource(R.drawable.dhrumil_shah);
}
}
@Override
protected void onHandleIntent(Intent intent) {
Uri data = Uri.EMPTY;
switch (intent.getFlags()) {
case (EXPORT_DB):
// Should be the file Uri we want to write to
Uri out = intent.getData();
break;
case (IMPORT_DB):
// Should be the file Uri we want to read from
Uri in = intent.getData();
break;
default:
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case Constants.REQUEST_CODE_LOGIN:
inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
navigationView.getMenu().performIdentifierAction(R.id.nav_wallet, 0);
}
if (data != null) {
if (Intent.ACTION_VIEW.equals(data.getAction())) {
QRCode qrCode = new QRCode();
Uri uri = data.getData();
qrCode.setAddress(uri.getQueryParameter("address:"));
qrCode.setAddress(uri.getQueryParameter("amount:"));
qrCode.setAddress(uri.getQueryParameter("message:"));
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.QRCODE, qrCode);
Fragment fragment = new NewTransferFragment();
fragment.setArguments(bundle);
showFragment(fragment, true);
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
String action = intent.getAction();
Uri uri = intent.getData();
Message msg = mHandler.obtainMessage();
msg.obj = uri.toString();
msg.arg1 = startId;
//Bundle data = new Bundle();
//data.putAll(intent.getExtras());
msg.setData(intent.getExtras());
if (action.equals(ACTION_RECORD_GPS)) {
msg.what = MSG_GET_LOCATION;
}
mHandler.sendMessage(msg);
}
return START_STICKY;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == MY_INTENT_CLICK) {
if (null == data) return;
Uri selectedImageUri = data.getData();
String selectedImagePath = FilePath.getPath(App.getContext(), selectedImageUri);
if (selectedImagePath != null)
App.getInstance().getPreferences()
.edit()
.putString("userInfoBg", selectedImagePath)
.putBoolean("isUserBackground", true)
.apply();
else
Toast.makeText(getActivity(), "Не могу прикрепить файл", Toast.LENGTH_SHORT).show();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (data != null && data.getData() != null) {
getContentResolver().takePersistableUriPermission(data.getData(),
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
FFMSettings.putDownloadUri(data.getData().toString());
}
}
super.onActivityResult(requestCode, resultCode, data);
}
/**
* 5.0以下 上传图片成功后的回调
*/
public void mUploadMessage(Intent intent, int resultCode) {
if (null == mUploadMessage) {
return;
}
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
Bitmap bitmap = ImageUtils.getBitmap(ImageUtils.getRealPathFromURI(this, uri), 2048, 1232);
if (bitmap != null)
detectFace(bitmap);
else
Toast.makeText(this, "Cann't open this image.", Toast.LENGTH_LONG).show();
}
}
static private boolean isProperIntent(Intent intent) {
return !(null == intent
|| TextUtils.isEmpty(intent.getAction())
|| null == intent.getData()
|| TextUtils.isEmpty(intent.getData().getSchemeSpecificPart())
|| ((intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED))
&& intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
)
);
}
/**
* 启动的时候根据bundle参数决定切换到哪个tab
*/
private void handleUriStartupParams() {
Intent intent = getIntent();
if (intent == null) {
return;
}
Uri uri = intent.getData();
if (uri == null) {
return;
}
// 这里要把data置空,否则每次进来锁屏解锁,都会触发这些逻辑
intent.setData(null);
String query = uri.getQuery();
// "param="这个字符串已经占了6个字符了,所以query的长度至少要有8(加上花括号)
if (query == null || query.length() < 8) {
return;
}
try {
// 通过uri.getQuery()得到的query已经是解码过的字符串了,不需要再decode
String jsonString = query.substring(6);
JSONObject json = new JSONObject(jsonString);
WebViewFragment webViewFragment = WebViewFragment.getInstance();
webViewFragment.loadUrl(json.getString("url"));
switchContent(webViewFragment);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String switchTypeForIntent(Intent data) {
String switchType = "unknown";
if (data != null) {
if (data.getData() != null || data.getBooleanExtra(BraintreeFragment.EXTRA_WAS_BROWSER_SWITCH_RESULT, false)) {
switchType = "browser-switch";
} else {
switchType = "app-switch";
}
}
return switchType;
}
private void processView(final Intent intent) {
if (intent == null) {
return;
}
if (intent.getData() == null) {
return;
}
if ("bitcoin".equals(intent.getData().getScheme())) {
String uri = "/uri/?uri=" + Uri.encode(intent.getData().toString());
super.loadUrl(getBaseURL() + "#" + uri);
} else if (intent.getData().getPath() == null) {
super.loadUrl(getBaseURL());
} else {
String path = intent.getData().getPath();
if (path.length() > 4 && path.charAt(0) == '/' && path.charAt(3) == '/') {
// hackish language URL detection
path = path.substring(3);
}
String url = getBaseURL() + "#" + path,
query = intent.getData().getQuery(),
fragment = intent.getData().getFragment();
if (path.startsWith("/wallet/")) {
if (fragment != null && !fragment.isEmpty()) {
url = getBaseURL() + '#' + fragment;
} else {
url = getBaseURL();
}
super.loadUrl(url);
} else if (path.startsWith("/pay/") || path.startsWith("/redeem/") || path.startsWith("/uri/")) {
if (query != null && !query.isEmpty()) {
url += "?" + query;
}
super.loadUrl(url);
} else { // not a wallet url - shouldn't happen given the filters work correctly
}
}
}
@Override
public void onNewIntent( Intent intent )
{
super.onNewIntent(intent);
if (intent != null)
{
Uri newData = intent.getData();
if (newData != null)
{
Log.d(TAG, "onNewIntent: " + newData);
setAlarmID(this, ContentUris.parseId(newData));
} else Log.w(TAG, "onNewIntent: null data!");
} else Log.w(TAG, "onNewIntent: null Intent!");
}
@Override
public void onReceive(Context context, Intent intent)
{
if(intent.getData() != null && "package".equals(intent.getData().getScheme()))
showPackageNotification(context, intent);
}
@Override
protected void onStart() {
super.onStart();
final Intent intent = getIntent();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
} else if (intent != null) {
try {
this.jidToEdit = Jid.ofEscaped(intent.getStringExtra("jid"));
} catch (final IllegalArgumentException | NullPointerException ignored) {
this.jidToEdit = null;
}
if (jidToEdit != null && intent.getData() != null && intent.getBooleanExtra("scanned", false)) {
final XmppUri uri = new XmppUri(intent.getData());
if (xmppConnectionServiceBound) {
processFingerprintVerification(uri, false);
} else {
this.pendingUri = uri;
}
}
boolean init = intent.getBooleanExtra("init", false);
boolean openedFromNotification = intent.getBooleanExtra(EXTRA_OPENED_FROM_NOTIFICATION, false);
Log.d(Config.LOGTAG, "extras " + intent.getExtras());
this.mForceRegister = intent.hasExtra(EXTRA_FORCE_REGISTER) ? intent.getBooleanExtra(EXTRA_FORCE_REGISTER, false) : null;
Log.d(Config.LOGTAG, "force register=" + mForceRegister);
this.mInitMode = init || this.jidToEdit == null;
this.messageFingerprint = intent.getStringExtra("fingerprint");
if (!mInitMode) {
this.binding.accountRegisterNew.setVisibility(View.GONE);
setTitle(getString(R.string.account_details));
configureActionBar(getSupportActionBar(), !openedFromNotification);
} else {
this.binding.avater.setVisibility(View.GONE);
configureActionBar(getSupportActionBar(), !(init && Config.MAGIC_CREATE_DOMAIN == null));
if (mForceRegister != null) {
if (mForceRegister) {
setTitle(R.string.register_new_account);
} else {
setTitle(R.string.add_existing_account);
}
} else {
setTitle(R.string.action_add_account);
}
}
}
SharedPreferences preferences = getPreferences();
mUseTor = QuickConversationsService.isConversations() && preferences.getBoolean("use_tor", getResources().getBoolean(R.bool.use_tor));
this.mShowOptions = mUseTor || (QuickConversationsService.isConversations() && preferences.getBoolean("show_connection_options", getResources().getBoolean(R.bool.show_connection_options)));
this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
if (mForceRegister != null) {
this.binding.accountRegisterNew.setVisibility(View.GONE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
String fileToUploadPath = null;
if (data.getData() != null) {
Log.i(
"[Chat Messages Fragment] Intent data after picking file is "
+ data.getData().toString());
if (data.getData().toString().contains("com.android.contacts/contacts/")) {
Uri cvsPath = FileUtils.getCVSPathFromLookupUri(data.getData().toString());
if (cvsPath != null) {
fileToUploadPath = cvsPath.toString();
Log.i("[Chat Messages Fragment] Found CVS path: " + fileToUploadPath);
} else {
// TODO Error
return;
}
} else {
fileToUploadPath =
FileUtils.getRealPathFromURI(getActivity(), data.getData());
Log.i(
"[Chat Messages Fragment] Resolved path for data is: "
+ fileToUploadPath);
}
if (fileToUploadPath == null) {
fileToUploadPath = data.getData().toString();
Log.i(
"[Chat Messages Fragment] Couldn't resolve path, using as-is: "
+ fileToUploadPath);
}
} else if (mImageToUploadUri != null) {
fileToUploadPath = mImageToUploadUri.getPath();
Log.i(
"[Chat Messages Fragment] Using pre-created path for dynamic capture "
+ fileToUploadPath);
}
if (fileToUploadPath.startsWith("content://")
|| fileToUploadPath.startsWith("file://")) {
Uri uriToParse = Uri.parse(fileToUploadPath);
fileToUploadPath =
FileUtils.getFilePath(
getActivity().getApplicationContext(), uriToParse);
Log.i(
"[Chat Messages Fragment] Path was using a content or file scheme, real path is: "
+ fileToUploadPath);
if (fileToUploadPath == null) {
Log.e(
"[Chat Messages Fragment] Failed to get access to file "
+ uriToParse.toString());
}
} else if (fileToUploadPath.contains("com.android.contacts/contacts/")) {
fileToUploadPath =
FileUtils.getCVSPathFromLookupUri(fileToUploadPath).toString();
Log.i(
"[Chat Messages Fragment] Path was using a contact scheme, real path is: "
+ fileToUploadPath);
}
if (fileToUploadPath != null) {
if (FileUtils.isExtensionImage(fileToUploadPath)) {
addImageToPendingList(fileToUploadPath);
} else {
addFileToPendingList(fileToUploadPath);
}
} else {
Log.e(
"[Chat Messages Fragment] Failed to get a path that we could use, aborting attachment");
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
} else {
if (FileUtils.isExtensionImage(mImageToUploadUri.getPath())) {
File file = new File(mImageToUploadUri.getPath());
if (file.exists()) {
addImageToPendingList(mImageToUploadUri.getPath());
}
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = GetPathFromUri4kitkat.getPath(MainActivity.this, uri);
final AlertDialog[] dialog = new AlertDialog[1];
final AlertDialog.Builder dialogB = new AlertDialog.Builder(this)
.setTitle("正在导入笔记...")
.setView(R.layout.layout_more_progress);
NotePersistenceController.importNote(path, new ImportNoteListener() {
@Override
public void beforeImport() {
dialog[0] = dialogB.show();dialog[0].setCancelable(false);
}
@Override
public void afterImport(int num) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
dialog[0].dismiss();
}
});
EventBus.getDefault().post(new DoneImportNoteEvent());
}
});
}
break;
case Define.ALBUM_REQUEST_CODE:
//更换图片背景
if (resultCode == RESULT_OK) {
ArrayList<String > imagePaths = data.getStringArrayListExtra(Define.INTENT_PATH);
if(imagePaths.size() ==1){
AppPreferenceUtil.setHeadBgPath(imagePaths.get(0));
try{
headBgImgaeView.setImageDrawable(
new BitmapDrawable(
ImageProcessor.zoomImageMin(
BitmapFactory.decodeFile(imagePaths.get(0))
, getResources().getDisplayMetrics().widthPixels
, getResources().getDisplayMetrics().widthPixels)
)
);
headBgImgaeView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}catch (Exception e){
headBgImgaeView.setImageDrawable(ImageProcessor.zoomImageMin(
ContextCompat.getDrawable(this, R.drawable.navigation_header)
, getResources().getDisplayMetrics().widthPixels
, getResources().getDisplayMetrics().widthPixels));
}
}
//You can get image path(ArrayList<String>
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}