Why does Unexpected implicit cast to `EditText`: layout tag was `TextView` - android-studio

I have a problem, I'm trying to finish the lesson Android fundamentals 02.3: Implicit intents, but there are some errors
the first one is Unexpected implicit cast to EditText: layout tag was TextView
the second one is Consider adding a declaration to your manifest when calling this \ method; see https://g.co/dev/packagevisibility for details
when running the application, it automatically stops immediately, I have tried it on the emulator and on real devices
source codelab : https://developer.android.com/codelabs/android-training-activity-with-implicit-intent?index=..%2F..%2Fandroid-training#0
Code MainActivity.java
package com.example.implicitintents;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebsiteEditText = findViewById(R.id.website_edittext);
mLocationEditText = findViewById(R.id.location_edittext);
mShareTextEditText = findViewById(R.id.share_edittext);
}
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void openLocation(View view) {
String loc = mLocationEditText.getText().toString();
Uri addressUri = Uri.parse("geo:0,0?q=" + loc);
Intent intent = new Intent(Intent.ACTION_VIEW, addressUri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void shareText(View view) {
String txt = mShareTextEditText.getText().toString();
String mimeType = "text/plain";
ShareCompat.IntentBuilder
.from(this)
.setType(mimeType)
.setChooserTitle("Share this text with: ")
.setText(txt)
.startChooser();
}
}
Code Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context="MainActivity">
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<Button
android:id="#+id/open_website_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openWebsite"
android:text="#string/button_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<Button
android:id="#+id/open_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openLocation"
android:text="#string/button_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
<Button
android:id="#+id/share_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="shareText"
android:text="#string/button_share" />
</LinearLayout>

In your xml file you declare three elements as Textview
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
And then in your activity you declare your variables as EditText
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
And that's why your seeing those errors of casting.
Change in your xml file to EditText if you want to input some data or leave it like TextView if you want display some text but change the type of your variables in the activity. Make sure both are the same type

Related

How can I pass the checked radio button value into text View in kotlin android studio?

I made a dialogue box and I put radio group in it and I add three radio button 1)male 2)female 3)others if user select male so the selected radio button male should be shown in text View
Here, I would like to share you here a simple app with both the activity and layout code. I hope this will help you.
First the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="100dp"
tools:context=".TestActivity">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="What is your gender?"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtViewGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="-- Selected Gender --"
android:textSize="16sp" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Select" />
</LinearLayout>
Second the Main Activity code
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class GenderActivity: AppCompatActivity() {
private lateinit var selectedGender: String
private var selectedGenderIndex: Int = 0
private val gender = arrayOf("Male", "Female", "Others")
private lateinit var txtViewGender: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test4)
txtViewGender = findViewById<TextView>(R.id.txtViewGender)
var androidButton: Button = findViewById<Button>(R.id.button)
androidButton.setOnClickListener {
showRadioDialog()
}
}
private fun showRadioDialog() {
selectedGender = gender[selectedGenderIndex]
MaterialAlertDialogBuilder(this)
.setTitle("Select your gender")
.setSingleChoiceItems(gender, selectedGenderIndex) { dialog, which ->
selectedGenderIndex = which
selectedGender = gender[which]
}
.setPositiveButton("Ok") { dialog, which ->
Toast.makeText(this, "Selected --> $selectedGender ", Toast.LENGTH_SHORT)
.show()
txtViewGender.text = selectedGender
}
.setNegativeButton("Cancel") { dialog, which ->
dialog.dismiss()
}
.show()
}
}
When you run the code, you will get the following two screens.
Screen 1
Screen 2

I have implemented the ability for my app to take a picture. Why is the file path null when I try to save the image locally?

This is my very first simple and almost-complete Android application.
My Goal
I want to take a picture with the device's built-in camera, display it on the ImageButton in that same Fragment, and have it save to the device locally so that I can reference its file path and add it to my custom SQLite Database to display in my RecyclerView on a different Fragment.
Background Info
My app is built on top of a custom SQLite Database backend containing two tables, users and their associated books that they've added to the app to be displayed in a RecyclerView.
The app is built entirely with Kotlin. Navigation is done using Android Jetpack's Navigation with a navigation graph (currently not using SafeArgs), and the entire app is run from a single MainActivity that holds multiple Fragments. I have a Fragment containing a RecyclerView, and this RecyclerView contains an ImageView where I hope to display the thumbnail of the picture that the user took with their device. To display images, I am using the 3rd-party Picasso library. The minimum API that my app is targeting is API 23. I am using the deprecated Camera API because Camera2 and CameraX had pretty much no improvement of my issue, so I fell back on this and it's not helping either.
My manifest contains these bits of code for Write access and Camera access permissions:
<uses-feature android:name="android.hardware.camera"
android:required="false"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
My file provider is set up as follows:
<provider
android:authorities="<my_package_authority>.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"
/>
</provider>
My file_paths.xml file is here:
<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="my_images"
path="Android/data/<my_package_authority>/files/Pictures">
</external-files-path>
<external-files-path
name="my_debug_images"
path="/storage/emulated/0/Android/data/<my_package_authority>/files/Pictures">
</external-files-path>
<external-files-path
name="my_root_images"
path="/">
</external-files-path>
</paths>
Here is my MainActivity.kt, which I use basically to store the request codes as well as the userID and bookID of the users and their books to upload to my database (patch-up solution to be better implemented later):
class MainActivity : AppCompatActivity() {
companion object {
val REQUEST_CAMERA_PERMISSIONS_CODE = 1
val REQUEST_CAMERA_USAGE = 2
var userID: Int? = null
var bookID: Int? = null
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
The .xml is completely unchanged and default.
Below is the .xml and .kt files for CreateBookFragment, the Fragment on which the user is going to add a book to their personal library.
fragment_create_book.xml (I am aware some of the bottom buttons clip out of the screen, depending on screen size. I plan to fix after the camera functionality is implemented)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/clCreateBookRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
tools:context=".CreateBookFragment">
<TextView
android:id="#+id/tvCreateBookTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="cursive"
android:shadowColor="#color/deep_red"
android:shadowDx="1.5"
android:shadowDy="1.5"
android:shadowRadius="1.5"
android:text="#string/add_book"
android:textColor="#color/deep_red"
android:textSize="55sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.024" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvCreateBookTitle">
<ImageButton
android:id="#+id/ibCreateBookImage"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center"
android:backgroundTint="#color/deep_red"
android:contentDescription="#string/add_a_picture_to_the_book"
android:src="#android:drawable/ic_menu_camera" />
<EditText
android:id="#+id/etCreateBookTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/title"
android:importantForAutofill="no"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<EditText
android:id="#+id/etCreateBookAuthor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/author"
android:importantForAutofill="no"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<EditText
android:id="#+id/etCreateBookPages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/total_pages"
android:importantForAutofill="no"
android:inputType="number"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/tvCreateBookGenre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:layout_marginEnd="10dp"
android:text="#string/genre"
android:textColor="#color/black"
android:textSize="18sp" />
<Spinner
android:id="#+id/spinCreateBookGenre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/genre"
android:importantForAutofill="no"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck,SpeakableTextPresentCheck" />
</LinearLayout>
<EditText
android:id="#+id/etCreateBookPublisher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/publisher"
android:importantForAutofill="no"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<EditText
android:id="#+id/etCreateBookYearPublished"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/year_published"
android:importantForAutofill="no"
android:inputType="number"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<EditText
android:id="#+id/etCreateBookISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/isbn_code"
android:importantForAutofill="no"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#color/black" />
<EditText
android:id="#+id/etCreateBookStarRating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"
android:ems="10"
android:hint="#string/star_rating_1_5"
android:importantForAutofill="no"
android:inputType="number"
android:minHeight="48dp"
android:textColorHint="#color/black"
tools:ignore="TextContrastCheck" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btnCancelCreateBook"
style="#style/cancel_button_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#android:string/cancel" />
<Button
android:id="#+id/btnSaveCreateBook"
style="#style/save_button_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
CreateBookFragment.kt
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.squareup.picasso.MemoryPolicy
import com.squareup.picasso.NetworkPolicy
import com.squareup.picasso.Picasso
import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
class CreateBookFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSelectedListener {
private var photoFilePath: String? = "" // This is returning null!
private var navigationController: NavController? = null
private lateinit var etCreateBookTitle: EditText
private lateinit var etCreateBookAuthor: EditText
private lateinit var etCreateBookPages: EditText
private lateinit var spinCreateBookGenre: Spinner
private lateinit var etCreateBookPublisher: EditText
private lateinit var etCreateBookYearPublished: EditText
private lateinit var etCreateBookISBN: EditText
private lateinit var etCreateBookStarRating: EditText
private lateinit var ibCreateBookImage: ImageButton
private lateinit var btnCancelCreateBook: Button
private lateinit var btnSaveCreateBook: Button
private lateinit var genres: Array<out String>
private lateinit var spinnerText: String
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_create_book, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navigationController = Navigation.findNavController(view)
initialiseUIElements(view)
setUpButtonClickListeners()
setUpGenreSpinner()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == MainActivity.REQUEST_CAMERA_USAGE && resultCode == Activity.RESULT_OK) {
val photoUri: Uri = Uri.parse(photoFilePath)
Picasso.with(requireContext())
.load(photoUri)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.error(R.drawable.ic_custom_bookshelf)
.fit()
.centerInside()
.noFade()
.into(ibCreateBookImage)
}
}
private fun initialiseUIElements(view: View) {
etCreateBookTitle = view.findViewById(R.id.etCreateBookTitle)
etCreateBookAuthor = view.findViewById(R.id.etCreateBookAuthor)
etCreateBookPages = view.findViewById(R.id.etCreateBookPages)
spinCreateBookGenre = view.findViewById(R.id.spinCreateBookGenre)
etCreateBookPublisher = view.findViewById(R.id.etCreateBookPublisher)
etCreateBookYearPublished = view.findViewById(R.id.etCreateBookYearPublished)
etCreateBookISBN = view.findViewById(R.id.etCreateBookISBN)
etCreateBookStarRating = view.findViewById(R.id.etCreateBookStarRating)
ibCreateBookImage = view.findViewById(R.id.ibCreateBookImage)
btnCancelCreateBook = view.findViewById(R.id.btnCancelCreateBook)
btnSaveCreateBook = view.findViewById(R.id.btnSaveCreateBook)
}
private fun setUpButtonClickListeners() {
ibCreateBookImage.setOnClickListener(this)
btnCancelCreateBook.setOnClickListener(this)
btnSaveCreateBook.setOnClickListener(this)
}
private fun setUpGenreSpinner() {
genres = resources.getStringArray(R.array.book_genres)
val spinnerAdapter: ArrayAdapter<CharSequence> = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, genres)
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinCreateBookGenre.adapter = spinnerAdapter
spinCreateBookGenre.onItemSelectedListener = this
}
private fun addBook(view: View) {
if (checkEmpty(etCreateBookTitle) || checkEmpty(etCreateBookAuthor) ||
(checkEmpty(etCreateBookPages) || !isNumeric(etCreateBookPages.text.toString().trim())) ||
spinnerText.isEmpty() || checkEmpty(etCreateBookPublisher) ||
(checkEmpty(etCreateBookYearPublished) || !isNumeric(etCreateBookYearPublished.text.toString().trim())) ||
checkEmpty(etCreateBookISBN) ||
(checkEmpty(etCreateBookStarRating) || !isNumeric(etCreateBookStarRating.text.toString().trim()))) {
Toast.makeText(requireContext(), "Fields cannot be blank", Toast.LENGTH_SHORT).show()
}
else {
val bookTitle: String = etCreateBookTitle.text.toString().trim()
val bookAuthor: String = etCreateBookAuthor.text.toString().trim()
val bookPages: Int = etCreateBookPages.text.toString().trim().toInt()
val bookGenre: String = spinnerText
val bookPublisher: String = etCreateBookPublisher.text.toString().trim()
val bookYearPublished: Int = etCreateBookYearPublished.text.toString().trim().toInt()
val ISBN: String = etCreateBookISBN.text.toString().trim()
val bookStarRating: Float = etCreateBookStarRating.text.toString().trim().toFloat()
val bookImage: String? = if (photoFilePath != "")
photoFilePath
else
null
val dbHandler: DBHandler = DBHandler(requireContext())
val status = dbHandler.addBook(BookModelClass(null, bookTitle, bookAuthor, bookPages,
bookGenre, bookPublisher, bookYearPublished, ISBN, bookStarRating, 0, bookImage, MainActivity.userID!!))
if (status > -1) {
Toast.makeText(requireContext(), "Successfully added book to list", Toast.LENGTH_SHORT).show()
etCreateBookTitle.text.clear()
etCreateBookAuthor.text.clear()
etCreateBookPages.text.clear()
etCreateBookPublisher.text.clear()
etCreateBookYearPublished.text.clear()
etCreateBookISBN.text.clear()
etCreateBookStarRating.text.clear()
}
}
}
private fun checkEmpty(editText: EditText): Boolean {
if (editText.text.toString().trim() == "") {
return true
}
return false
}
override fun onClick(p0: View?) {
when (p0) {
ibCreateBookImage -> {
if (ContextCompat.checkSelfPermission(requireContext(), android.Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED)
startCamera()
else {
ActivityCompat.requestPermissions(requireActivity(), arrayOf(android.Manifest.permission.CAMERA),
MainActivity.REQUEST_CAMERA_PERMISSIONS_CODE)
}
}
btnCancelCreateBook -> {
navigationController!!.navigate(R.id.action_createBookFragment_to_bookListFragment)
Toast.makeText(requireContext(), "Changes discarded", Toast.LENGTH_SHORT).show()
}
btnSaveCreateBook -> {
addBook(p0)
navigationController!!.navigate(R.id.action_createBookFragment_to_bookListFragment)
}
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == MainActivity.REQUEST_CAMERA_USAGE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)
startCamera()
else {
Toast.makeText(requireContext(), "Oops! Camera permission denied", Toast.LENGTH_SHORT).show()
return
}
}
}
private fun startCamera() {
val cameraIntent: Intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
var photoFile: File? = null
try {
photoFile = createPictureFile()
} catch (exception: IOException) {
Toast.makeText(requireContext(), "Error: Cannot save photo", Toast.LENGTH_SHORT).show()
return
}
if (photoFile != null) {
val photoUri = FileProvider.getUriForFile(requireContext(), requireActivity().packageName + ".fileprovider", photoFile)
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri)
startActivityForResult(cameraIntent, MainActivity.REQUEST_CAMERA_USAGE)
}
}
private fun createPictureFile(): File {
val timeStamp: String = SimpleDateFormat("ddMMyyyy_HHmmss", Locale.UK).format(Date().time)
val photoFileName: String = "IMG_" + timeStamp + "_"
val storageDirectory: File = requireContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!
return File.createTempFile(photoFileName, ".jpg", storageDirectory).apply {
photoFilePath = absolutePath
}
}
private fun isNumeric(string: String): Boolean {
return string.all { char -> char.isDigit() }
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
spinnerText = genres[p2].toString()
}
override fun onNothingSelected(p0: AdapterView<*>?) {
spinnerText = ""
}
}
The Issue
In reality, when trying to save the picture to the device, Android Studio registers the picture/path as "null", and I used to get a NullPointerException when trying to load the pictures on the RecyclerView before I started using Picasso, even when I can see the picture was indeed saved to local storage on the emulator (API 30) and on a physical device (API 24) with the path set to: "/storage/emulated/0/Android/data/<my_package_authority>/files/Pictures/IMG_01062022_164449_8511882897552656984.jpg" for the emulator and a similar path for the physical device (file_paths.xml included below). I got this path by using an application called DBBrowser for Sqlite, which I used to confirm that my database is indeed getting the path.
Picasso is only displaying the error image that I have set for the thumbnail, despite trying so many different sources such as the official Android docs and some other forums, videos and other StackOverflow questions/answers of a similar topic. When the user tries to add a picture to their book when creating it at first, it doesn't even actually show the picture after they've taken a camera picture. What appears to happen is that the file is never "officially" created, but the file does exist at the specified location on device memory. I am currently using the deprecated startActivityForResult() function for testing purposes and trying to set things in onActivityResult() inside the Fragment, but it's not working. I am using the deprecated function because the newer functions that replace it aren't helping either, so it was kind of a last-resort thing. An answer on StackOverflow suggested that the startActivityForResult() function is actually sending the data to the MainActivity instead of localising that data in the Fragment, which has pretty much caused the biggest headaches. It's been days, if not an entire week with this issue, send help...
I do not need any help with trying to display images or even trying to get the image path from my database, I only need help figuring out how to stop the file path from returning null so that Picasso can display the image preview when the user first adds the image on CreateBookFragment. If the file path can stop returning null, I can get this entire functionality going. I debated putting my database here with the two model classes, but it's like 1 000 lines of code and StackOverflow doesn't allow more than 40 000 characters.
A Few Sources (definitely not all of them)
https://developer.android.com/training/camera/photobasics
onActivityResult is not being called in Fragment
One of the MANY Youtube videos I've watched: https://www.google.com/search?q=how+to+save+an+image+from+camera+onto+device+android+studio&rlz=1C1CHBF_enZA979ZA979&oq=how+to+save+an+image+from+camera+onto+device+android+studio&aqs=chrome..69i57j0i22i30l2j0i390.10856j0j7&sourceid=chrome&ie=UTF-8#kpvalbx=_fW2YYqCeCJq6gAbewp2gCA22
Edit:
As a quick and dirty solution, I ended up saving the captured images as blobs in my SQLite database and converting them to bitmaps when it came time to displaying them on my ImageViews. I am still looking for a more efficient way to do this, as storing images as blobs in SQLite database isn't best practice.

Android: RecyclerView's CardView Not Showing Every Time

I have a RecyclerView in MainActivity that shows a list of CardViews and that is working properly. A click on the CardView finishes the RecyclerView Activity and launches a Detail Activity that shows the clicked on CardView in a new RecyclerView list. The Detail Activity is used only to show that single CardView in a RecyclerView (I do this so I can use RecyclerView's ItemTouchHelper.SimpleCallback code on the CardView for easy left swipe for the user).
Here is the problem: I hit the left caret on the Detail Activity's Toolbar to return to the MainActivity. Then a click on the exact same CardView brings the user back to the Detail Activity. But this time only the background View (a border) is showing. The view of the CardView and its database data is completely missing.
The error appears to happen randomly. I can click to go from the MainActivity to the Detail Activity back and forth 5 times successfully and then on the sixth try, no CardView will show in the Detail Activity. Or I'll click two times successfully and then the third time, the CardView in the Detail Activity will not show. Note the left caret click in Detail Activity uses onBackPressed() so the Detail Activity finishes. So I don't think there should be any backstack issues. I also tried to adjust the xml height for the CardView to match_parent rather than wrap_content but no luck. The Detail Activity's ViewModel to Repository to Dao returns a List wrapped in LiveData. Perhaps there is an observer problem with the ViewModel, but I thought the observer gets removed/destroyed when the Detail Activity is destroyed? What am I missing here?
Adapter
...
itemHolder.cardView.setOnClickListener(view -> {
Card adapterItem= TodosAdapter.this.getItem(itemHolder.getAdapterPosition());
int adapPos = itemHolder.getAdapterPosition();
if (adapPos !=RecyclerView.NO_POSITION) {
onItemClick(adapPos, adapterItem);
}
});
MainActivity
...
public void onItemClick(int clickPos, Card cardFromClick) {
Intent intent = new Intent(MainActivity.this, DetailActivity.class);
intent.putExtra("TAG","fromMain");
intent.putExtra("itemFromMain", cardFromClick);
startActivity(intent);
finish();
DetailActivity
...
public class DetailActivity extends AppCompatActivity {
private int cardId = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
// Get a new or existing ViewModel from the ViewModelProvider.
detsViewModel = new ViewModelProvider(this).get(CardViewModel.class);
Toolbar toolbar = findViewById(R.id.toolbar);
// The left caret is for Up navigation to the previous activity
// for OS versions 4.0 and earlier.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(R.drawable.ic_action_previous_item);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
String classname = extras.getString("TAG");
// The user clicked on a Card in the MainActivity
if (classname != null && classname.equals("fromMain")) {
card = extras.getParcelable("itemFromMain");
if (card != null) {
cardId = card.getId(); // card data is stored in Room database.
}
}
}
detsViewModel.getSingleCard(cardId).observe(this, singleAdapterList -> {
adapter2.setCardList(singleAdapterList);
});
}
activity_details.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".DetailsActivity" >
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" >
</include>
<RelativeLayout
android:id="#+id/todoListLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar" >
<TextView
android:id="#+id/Card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="Card"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_centerHorizontal="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/details_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="#+id/Card"
android:scrollbars="vertical" />
<TextView
android:id="#+id/skytext5"
android:text="Cards"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/details_recyclerview"
android:background="#color/colorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:clickable="true"
android:focusable="true" />
</RelativeLayout>
DetailsAdapter
...
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mContext).inflate(R.layout.details_list_item, parent, false);
}
private List<Card> oneCardList
public void setCardList(List<Card> singleCardList) {
if (oneCardList != null) {
oneCardList.clear();
this.oneCardList = singleCardList;
} else {
// First initialization
this.oneCardList = singleCardList;
}
}
details_list_item.xml
...
<FrameLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/detsinglecard_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:foreground="?android:attr/selectableItemBackground"
android:background="#FFFFFF"
tools:context=".DetailActivity">
<RelativeLayout
android:id="#+id/view_background2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
...
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_foreground2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorFlLabelFinal" >
<androidx.cardview.widget.CardView
android:id="#+id/cardview_dets"
android:layout_height="match_parent"
android:layout_width="match_parent"
...
}
ViewModel
...
LiveData<List<Card>> getSingleCard(int cardId) {
return repository.getSingleCard(cardId);
}
Repository
...
public LiveData<List<Card>> getSingleCard(int cardId) {
return quickcardDao.getSingleCard(cardId);
}
Dao
...
#Query("SELECT * FROM cards WHERE cardId = :cardId LIMIT 1")
LiveData<List<Card>> getSingleCard(int cardId);
So if the data does not change then going back to the same DetailActivity will not refresh the View. The answer was to re-use the LiveData (rather than re-loading the LiveData again from the database) if the data has not changed. See the Android Developers Architecture Components guide for ViewModel, "Implement a ViewModel" section for the "loadUsers()" example that solved my problem: https://developer.android.com/topic/libraries/architecture/viewmodel.

Android Studio: Click TextView to open an Specific Image on other Activity (Click Index Title to Open page on other Activity)

I m Developing Book Reading Project on Android studio, it has index activity with all titles and page numbers, when some one click on any title of index so on the an other activity the specific image should be open. all images are in Drawable folder.
here is XML Coding of First Activity coding Activity_main3.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2"
android:gravity="center"
android:shrinkColumns="1">
<TableRow
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/textview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="ناشر پاران...5"
android:textAppearance="?android:attr/textAppearanceLarge" />
/>
<TextView
android:id="#+id/textview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="پنهنجي پاران...6"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
The Second Activty coding is like this Activity_main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.sindhila.www.sindhi_school_linguistics.MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/SwitchImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:text="Next"
app:layout_constraintBaseline_toBaselineOf="#+id/SwitchImage2"
app:layout_constraintEnd_toStartOf="#+id/SwitchImage2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#mipmap/pic3" />
<Button
android:id="#+id/SwitchImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="Previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/SwitchImage" />
and Here is Coding Of mainactivity.java
it has two buttons for next and previous page and an image view to open images from drawable folder
package org.sindhila.www.sindhi_school_linguistics;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import java.util.Locale;
import uk.co.senab.photoview.PhotoViewAttacher;
public class MainActivity extends AppCompatActivity {
private static ImageView imageView;
private static Button SwitchImage;
private static Button SwitchImage2;
//
PhotoViewAttacher photoViewAttacher;
////
private int current_image_index;
int images[] = {R.mipmap.pic1, R.mipmap.pic2, R.mipmap.pic3,
R.mipmap.pic4,
R.mipmap.pic5,
R.mipmap.pic6,
R.mipmap.pic7,
R.mipmap.pic8,
R.mipmap.pic9,
R.mipmap.pic10,
R.mipmap.pic11,
R.mipmap.pic12,
R.mipmap.pic13,
R.mipmap.pic14,
R.mipmap.pic15,
R.mipmap.pic16,
R.mipmap.pic17,
R.mipmap.pic18,
R.mipmap.pic19,
R.mipmap.pic20,
R.mipmap.pic21,
R.mipmap.pic22,
R.mipmap.pic23,
R.mipmap.pic24,
R.mipmap.pic25,
R.mipmap.pic26,
R.mipmap.pic27,
R.mipmap.pic28,
R.mipmap.pic29,
R.mipmap.pic30,
R.mipmap.pic31,
R.mipmap.pic32,
R.mipmap.pic33,
R.mipmap.pic34,
R.mipmap.pic35,
R.mipmap.pic36,
R.mipmap.pic37,
R.mipmap.pic38,
R.mipmap.pic39,
R.mipmap.pic40,
R.mipmap.pic41,
R.mipmap.pic42,
R.mipmap.pic43,
R.mipmap.pic44,
R.mipmap.pic45,
R.mipmap.pic46,
R.mipmap.pic47,
R.mipmap.pic48,
R.mipmap.pic49,
R.mipmap.pic50,
R.mipmap.pic51,
R.mipmap.pic52,
R.mipmap.pic53,
R.mipmap.pic54,
R.mipmap.pic55,
R.mipmap.pic56,
R.mipmap.pic57,
R.mipmap.pic58,
R.mipmap.pic59,
R.mipmap.pic60,
R.mipmap.pic61,
R.mipmap.pic62,
R.mipmap.pic63,
R.mipmap.pic64,
R.mipmap.pic65,
R.mipmap.pic66,
R.mipmap.pic67,
R.mipmap.pic68,
R.mipmap.pic69,
R.mipmap.pic70,
R.mipmap.pic71,
R.mipmap.pic72,
R.mipmap.pic73,
R.mipmap.pic74,
R.mipmap.pic75,
R.mipmap.pic76,
R.mipmap.pic77,
R.mipmap.pic78,
R.mipmap.pic79,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
//////
imageView = (ImageView)findViewById(R.id.imageView);
Drawable drawable = getResources().getDrawable(R.mipmap.pic1);
imageView.setImageDrawable(drawable);
photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.update();
//////
}
public void buttonClick() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage = (Button) findViewById(R.id.SwitchImage);
SwitchImage.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
current_image_index++;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
);
}
public void buttonClick2() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage2 = (Button) findViewById(R.id.SwitchImage2);
SwitchImage2.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
if (current_image_index!=0) {
current_image_index--;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
}
);
}
}
Every thing is working Fine, i need to have hyperlink on Textview (on Activity_main3.xml and Main3Activity.java) to open specific image on Activity_main.xml/MainActivity.java
i have used following Coding but it produce error how to solve it please help. i want to click a textview on one activity and open specific image on other activity in imageview
in xml file of first activity in textview i added
android:onClick="onClick"
android:clickable="true"
.... added coding to first index activity named Main3activity.java where textviews are placed when I click textview it should open other activity and an image in it
public void onClick(View v) {
Intent intent = new Intent(Main3Activity.this,
MainActivity.class);
intent.putExtra("pic", pic4.png);
startActivity(intent);
} ...
and this coding to mainactivity.java where image should be opened in image view
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
setContentView(R.mipmap.pic1);
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageResource(getIntent().getIntExtra("img", 0));

Vitamio full screen videoview

I try to play live streaming with Vitamio. I fixed some problems however I can't fix this problem. Video doesn't play in fullscreen. These are my codes. I hope you can help me! Thank you and sorry for my bad English.
package com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity{
VideoView videoView;
private void Trt1(){
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
}
}
<?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" >
<io.vov.vitamio.widget.CenterLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<io.vov.vitamio.widget.VideoView
android:id="#+id/VideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>
Put the VideoView in a RelativeLayout and set it as:
<io.vov.vitamio.widget.VideoView
android:id="#+id/vitamioView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
Use this method to stretch your videoview in onCreate() method of your activity
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
To handle onConfigurationChange();
use below code
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "LANDSCAPE");
} else {
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "PORTRAIT");
}
}
also add this in your activity menifest file
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_STRETCH, 0);
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_ORIGIN, 0);
}
thank #Qadir Hussain
.it work for me
If using live streaming, then
there is a layout file for live streaming with the name of "mediaplayer_2.xml"
change the layout with following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<io.vov.vitamio.widget.CenterLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
</SurfaceView>
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>
Through this way i resolve my issue.
`package com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity{
private VideoView mVideoView;
private void Trt1(){
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
mVideoView = (VideoView) findViewById(R.id.VideoView);
mVideoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
mVideoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
}
}`

Resources