Android Picasso how can I load image - android

add in build.gradle library picasso
add permission in Manifest file
add ImageView to layout
in MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
String urlPath = "http://217.175.38.5:53389/photo/employee/262421?lastmod=1649263637";
Glide
.with(this)
.load(urlPath)
.into(imageView);
Picasso
.get()
.load(urlPath)
.into(imageView);
}
I decided to try Glide, but it doesn't work too

Because you must to load url with https or in manifest add this line
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>

Related

Why my android studio web view app goes blank white after splash screen in signed release and works perfect id debug?

Some how it works on older devices but i tried in 2 new devices the release app doesnt work its shows a white blank screeen after splash screen
And there is no error showing please answer me
main activity
private WebView mywebview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mywebview.getSettings();
mywebview.setWebViewClient(new WebViewClient());
mywebview.loadUrl("https://netixshop.com/");
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
}
public class myWebClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public void onBackPressed() {
if (mywebview.canGoBack()) {
mywebview.goBack();
}else{
super.onBackPressed();
}
}
}
here is my manifest
pleasse check this out and find why is the error caused
android manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity"></activity>
<activity android:name=".splashactivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>```
Probably you didn't add the internet permission to Manifest file while it is added to debug manifest file by default. So you need to add the internet permission;
<uses-permission android:name="android.permission.INTERNET" />
and if you work with android 8 or above, probably you will need to add this line under application tag for accessing to non-https web urls;
android:usesCleartextTraffic="true"
finally it will look like this;
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>

No sound with latest MediaManager 0.9.7 and Xamarin.Forms: 4.5.0.495

1. Init CrossMediaManager on MainActivity
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
CrossMediaManager.Current.Init(this);
LoadApplication(new App());
}
2. Click on button to Execute the play function
var mediaItem = await CrossMediaManager.Current.Play("http://tasfiaradio.servemp3.com:8000/tasfia1");
Same with
IMediaItem mediaFile = await CrossMediaManager.Current.Extractor.CreateMediaItem("http://tasfiaradio.servemp3.com:8000/tasfia1");
var mediaItem = await CrossMediaManager.Current.Play(mediaFile);
Expected behavior
hearing sound
Configuration
Plugin.MediaManager: 0.9.7
Xamarin.Forms: 4.5.0.495
By default, Android allows only https traffic, adding android:usesCleartextTraffic="true" to application tag worked for me. Below is the AndroidManifest configuration file content.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" package="com.testcrossmediaplayer"
android:installLocation="auto" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" />
<application android:label="Test Cross Media Player" android:usesCleartextTraffic="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

How do they load a url inside a webview instead of androids internal browser?

I'm trying to achieve this: MKyong - WebView.
To get a hint at what exactly, then take a look at the last picture before "Download Source Code".
My applications code is:
bookingView = (WebView) findViewById(R.id.fullscreen_content);
bookingView.getSettings().setJavaScriptEnabled(true);
bookingView.loadUrl("http://www.google.com");
But what that code does is opening the url(in this case Google) inside the default browser/internal browser in android and it's not meant to be that in the android application I am making.
Any ideas?
Add this line before the loadUrl() call
bookingView.setWebViewClient(new WebViewClient());
This is the answer:
Features
Load a URL on WebView
Open another page in the website on Webview dont on local Browser.
If you press on backbutton will go to the before page dont out of app.
MainActivity.java
public class MainActivity extends AppCompatActivity {
WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView)findViewById(R.id.webview);
webView();
}
//Metodo llamar el webview
private void webView(){
//Habilitar JavaScript (Videos youtube)
webview.getSettings().setJavaScriptEnabled(true);
//Handling Page Navigation
webview.setWebViewClient(new MyWebViewClient());
//Load a URL on WebView
webview.loadUrl("http://stackoverflow.com/");
}
// Metodo Navigating web page history
#Override public void onBackPressed() {
if(webview.canGoBack()) {
webview.goBack();
} else {
super.onBackPressed();
}
}
// Subclase WebViewClient() para Handling Page Navigation
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("stackoverflow.com")) { //Force to open the url in WEBVIEW
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Include this in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webview" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
RESULT
START PAGE
ANOTHER PAGE IN THE WEBSITE ON WEBVIEW

I want to add advertising in android application

I want to add "ads" in my project. I have created an ad using the website admob.com I just need to know how can i add it to my project. I searched on google but I am not getting the correct answers. Please Help. Thanks in advance.
Here are simple steps to add an ad banner in your android app.
Firstly add this method in your Main activity
private void displayAd()
{
try
{
AdView adView = new AdView(LettersType.this, AdSize.BANNER, HERE-YOUR-ADMOB-ID);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
FrameLayout adMobLayout = (FrameLayout)findViewById(R.id.banner);
// Add the adView to it
adMobLayout.addView(adView);
// AdRequest adRequest = new AdRequest();
// adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
adView.setAdListener(new AdListener() {
public void onDismissScreen(Ad arg0) {
}
public void onLeaveApplication(Ad arg0) {
}
public void onPresentScreen(Ad arg0) {
}
public void onReceiveAd(Ad arg0) {
}
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
}
});
}catch(Exception e)
{
}
}
Add this permissions in android manifest
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
And finally add this in your mainactivity layout XML file
<FrameLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/banner"
android:layout_centerHorizontal="true"
/>
This framelayout is the adbanner .

How to set the title not display?

It can remove title by setting requestWindowFeature(Window.FEATURE_NO_TITLE) in onCreat(). But the title display first, then disappear. How could the title not display? Could it set in manifest file?
Use like this in your manifest file:-
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
just permission in activity which u want to have no title
android:theme="#android:style/Theme.NoTitleBar"
use like this way..
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
If you just want the default theme and no title, you can put this in your manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
You can also set it from the Theme drop-down menu above your layout in eclipse.
You should always use the requestWindowFeature(Window.FEATURE_NO_TITLE) before using the setContentView
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.your_layout);
}

Categories

Resources