How to open an url in specifying browser from transparent activity?
I'm using the code:
public void open() {
Log.d("info","start");
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setData(Uri.parse("http://rambler.ru"));
i.setAction("com.android.browser");
ComponentName comp = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
i.setComponent(comp);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(
i);
finish();
}
but it doesn't work.
Browser is already opened
Use below code:
String url= "your url"
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Url));
startActivity(browserIntent);
Related
how when clicked onclick button whatsapp messages can be sent automatically
public void onclick(){
boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
if (isWhatsappInstalled) {
Uri uri = Uri.parse("smsto:" + "628124291xxxx");
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.putExtra(Intent.EXTRA_TEXT, "hallo");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} else {
Toast.makeText(MainActivity.this, "WhatsApp not Installed",
Toast.LENGTH_SHORT).show();
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goToMarket);
}
}
I don't know if it's the way you want it. I believe it is a way of doing. Try this.
String toNumber = "628124291xxxx";
String url = "https://api.whatsapp.com/send?phone="+ toNumber;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("com.whatsapp"); //com.whatsapp or com.whatsapp.w4b
i.setData(Uri.parse(url));
startActivity(i);
I get the following error below
startActivity (android.content.intent) in activity cannot be applied to (intent)
For this code - I have tried many different things - is there anything I need to add to the manifest? Thank you so much for your help!
img = (ImageView) findViewById(R.id.Fb);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent browserintent = new intent("android.intent.action.VIEW", Uri.parse("www.yahoo.com"));
startActivity(browserintent);
}
}
Change your code to this
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yahoo.com"));
startActivity(browserIntent);
You are missing a scheme http or https in your Uri:
Intent browserintent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yahoo.com"));
startActivity(browserintent);
Try this code
Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.yahoo.com"));
startActivity(intent);
i want open a file with hp ePrint exclusively...but with my code, file is opened with adobe reader...i don't know why....
THANKS IN ADVANCE!
public void viewPDF() {
String path = "/sdcard/droidText/ciccia.pdf";
try {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent=new Intent();
intent.setPackage("com.hp.android.print");
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
startActivity(intent);
}catch(ActivityNotFoundException anfe){
final String appPackageName="com.hp.android.print";
try{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=" +appPackageName)));
}catch(android.content.ActivityNotFoundException anfer){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id=" +appPackageName)));
}
}
}
Intent intent=new Intent();
intent.setPackage("com.hp.android.print")
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
You redeclared the intent object.
We are building a camera app that saves photos in a specific folder in the gallery. And we have to open the folder of our app in the gallery using an intent. We are using this code however it shows all folders.
View.OnClickListener goToGallery = new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
};
To open gallery I use this intent.
public static final int RESULT_GALLERY = 0;
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent , RESULT_GALLERY );
Try this code.
It will retrieve view pictures under storage/emulated/0/Pictures/MyAppPics
You can change the file path according to your directory path.
File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File f = new File(sdDir, "MyAppPics");
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.withAppendedPath(Uri.fromFile(f), "/MyAppPics"), "image/*");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
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.