Anyone knows the intent to search directly through the official Duckduckgo app on Android?
Tried this one so far, i think they dont have a query key in extras
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.duckduckgo.mobile.android");
intent.putExtra("query", subject);
context.startActivity(intent);
It is actually pretty simple than i thought
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://duckduckgo.com/?q=" + subject));
try {
intent.setPackage("com.duckduckgo.mobile.android");
context.startActivity(intent);
} catch (ActivityNotFoundException a) {
intent.setPackage(null);
context.startActivity(intent);
}
Related
My code is, at the moment like this:
When the user clicks on an audio file in my file manager, it should open it on their default audio app, but the file manager app just crashes. It also happens with apk and pdf files, but I removed those from the code to focus on the mp3 problem.
Also, if anyone knows a universal way to open files without specifying an extension, it would be amazing!
Thanks in advance, my friends.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
if (files[position].toString().contains(".png") || files[position].toString().contains(".jpg") || files[position].toString().contains(".jpeg")) {
intent.setDataAndType(Uri.parse(files[position].toString()), "image/jpeg");
} else if (files[position].toString().contains(".mp4")) {
intent.setDataAndType(Uri.parse(files[position].toString()), "video/*");
} else if (files[position].toString().contains(".mp3")) {
intent.setDataAndType(Uri.parse(files[position].toString()), "audio/*");
} else if (files[position].toString().contains(".doc") || files[position].toString().contains(".docx")) {
intent.setDataAndType(Uri.parse(files[position].toString()), "application/msword");
} else {
intent.setDataAndType(Uri.parse(files[position].toString()), "*/*");
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
You can use intent like this,
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "audio/*");
startActivity(intent);
I don't understand what you did in the code, but if you have the uri to the mp3 file, just use intent.
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
edit: I checked my codebase for a use like this, I opened a txt file for an import. Setting a type always crashed the app for me, hence I set the type to "* /*". See below for a similar code that works.
public void importDictionary() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*"); //needed to not make it crash
startActivityForResult(intent, 2);
}
Override onActivityResult for action afterwards
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
// your code here
}
}
I want to choose a file via an Android File Manager.
so, to open file intent code is
Intent intent = new Intent();
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), 1);
But I was unable to access file manager in samsung devices to resolve this problem i do
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, 1);
But this code in not working in other devices so what should i do to open file manager in all devices ?
private void openFile(int requestCODE) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(intent, requestCODE);
}
Does anyone know where can I find a full list of settings?
This is my code it works, the only problem I have I cannot find the line to bring up the google voice settings I'm looking for:
if (Build.VERSION.SDK_INT >= 14){
Intent intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}else {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I'm trying to use the following intent code to add in an if else statement to redirect if login is successful after displaying the toast message under
if (password.equals(storedPassword)) { but I get an "Cannot resolve constructor error.
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
if (password.equals(storedPassword)) {
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this, "Username or Password incorrect.", Toast.LENGTH_LONG).show();
}
}
});
like this
if (password.equals(storedPassword)) {
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
dialog.dismiss();
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "Username or Password incorrect.", Toast.LENGTH_LONG).show();
}
}
});
I have an ImageView that is visible in Preview, but is not shown in the emulator. I have already clean/build the project and sync gradle files. What could be the issue?
Do you use this from an anonymous inner class? Then thisrefers to the inner class instead of the activity. Use this instead (like you did with the toasts):
Intent intent = new Intent(MainActivity.this, HomeActivity.class);
startActivity(intent);
Change your intent definition to this :
Intent intent = new Intent(MainActivity.this, HomeActivity.class);
I look at how you call your toast and I infer that your lines of codes are in a inner class, so to refer to your activity context, you need to use MainActivity.this.
Replace this with current activity and for better experience alwyas use a try and catch block for this kind of intent
i have an image file path stored in my database. Now using it i want to open images from SD Card in my gallery. How can i do that. I have seen methods from Uri and using this method but i am getting error
File file = new File(filename);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("image/*");
startActivity(intent); /** replace with your own uri */
How to fix it,
04-20 08:42:23.516: E/AndroidRuntime(16815): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/My%20App/image_umxto_1.jpg }
best regards
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filename)), "image/*");
startActivity(intent);
Use this code and tell me
You can also use the below code:::
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
you can use the below line to do your task:::
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */
I was getting FileUriExposedException and after some digging found solution. Convert file path to URI and pass it in intent.
MediaScannerConnection.scanFile(getContext(),
new String[] { getImagePath() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("onScanCompleted", uri.getPath());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
});
Hope it helps.