How to use Firebase Remote Config for this? - android

How can I change whenever I need the Videoview URL using the Google Firebase Remote config method?
More details: I have a VideoView that uses URL to show video or stream but I want to be able to change these links whenever I need. Without having to create a new application update!
My activity:
package tk.protvapp.protv;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;
public class FoxActivity extends Activity {
VideoView myVideoView;
View v;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_fox);
myVideoView = (VideoView)this.findViewById(R.id.videofox1); MediaController mc = new MediaController(this); myVideoView.setMediaController(mc);
final String urlStream = "//Search the link in remote config for paste here";
myVideoView.start();
myVideoView.findFocus();
runOnUiThread(new Runnable() { #Override public void run() { myVideoView.setVideoURI(Uri.parse(urlStream)); } });
}
public void voltarhomefox(View v){
Intent intent = new Intent(FoxActivity.this, HomeActivity.class);
startActivity(intent);
}
}
My Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
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="#000"
tools:context="tk.protvapp.protv.FoxActivity">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="voltarhomefox"
android:text="VOLTAR" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/frameLayout">
<VideoView
android:id="#+id/videofox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout>

You can define a key in Remote Config Dashboard
video_url = "https://foo.com/video.mp4"
and fetch the value of video_url from your code using the getString("video_url") method.

Related

React-native Android Splashscreen - Custom fonts

I created a splashscreen for my react-native app and have to implement TextView with custom fonts.
I created an Android layout specifically for the splashscreen with res/layout/launch_screen.xml and the TextViews appears but without custom fonts then i launch that on splashActivity file.
But it's strange because when i inject the layout directly on the mainActivity file the fonts seems be loaded.
So i think it's due to the fonts path in SplashActivity file but the code seems be ok.
Here are the files :
SplashActivity.js :
package com.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.graphics.Typeface;
import android.content.res.AssetManager;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launch_screen);
TextView txt_1 = (TextView) findViewById(R.id.din_bold);
Typeface font_1 = Typeface.createFromAsset(getAssets(), "fonts/DinCondBold.otf");
txt_1.setTypeface(font_1);
TextView txt_2 = (TextView) findViewById(R.id.din_light);
Typeface font_2 = Typeface.createFromAsset(getAssets(), "fonts/DinCondLight.otf");
txt_2.setTypeface(font_2);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.js
package com.app;
import android.app.Activity;
import com.facebook.react.ReactActivity;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SplashScreen.show(this, R.style.SplashScreenTheme);
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "app";
}
}
And launch_screen.xml
<LinearLayout 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="#drawable/background"
android:gravity="center"
android:orientation="vertical"
tools:context="com.mitsu.MainActivity">
<TextView
android:id="#+id/din_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCAN PRODUITS"
android:textColor="#eb212e"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="#+id/din_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIENVENUE"
android:textColor="#717171"
android:textSize="36sp" />
<ImageView
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_marginTop="14dp"
android:src="#drawable/splash_logo" />
</LinearLayout>
Does anyone know what's going on?

Using remote config from firebase to change URL of videoView

What I need is: Change the URL of the video view whenever I change the remote config parameters!
I'm making a tv channel app using video view.
   to show the TV channels if the format of the url .m3u8 is used, but this link changes daily so IMPOSSIVEL I stay updating my application every day that change this link .... so I discovered (actually I remembered) that in firebase there is a option "remote config" that it is possible to change these links ...
   
  What do I want anyway? How can I do this by using the remote config
package tk.protvapp.protv;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;
public class FoxActivity extends Activity {
VideoView myVideoView;
View v;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_fox);
myVideoView = (VideoView)this.findViewById(R.id.videofox1); MediaController mc = new MediaController(this); myVideoView.setMediaController(mc);
final String urlStream = "//Search the link in remote config for paste here";
myVideoView.start();
myVideoView.findFocus();
runOnUiThread(new Runnable() { #Override public void run() { myVideoView.setVideoURI(Uri.parse(urlStream)); } });
}
public void voltarhomefox(View v){
Intent intent = new Intent(FoxActivity.this, HomeActivity.class);
startActivity(intent);
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
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="#000"
tools:context="tk.protvapp.protv.FoxActivity">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="voltarhomefox"
android:text="VOLTAR" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/frameLayout">
<VideoView
android:id="#+id/videofox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout>

string aren't passing between my activities maybe xml issue in android studio

Please help me figure out why my string isn't passing between my activities in android studio. I ran this script on my phone but the string I'm passing from my main activity is passing to my secondary activity. I'm going through an android teach yourself book and I believe the issue is in my XML.
Here's my XML code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.owner.hour3application.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
activity_secondary.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.owner.hour2application.SecondaryActivity">
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.design.widget.CoordinatorLayout>
Main Activity
package com.example.owner.hour2application;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button activityButton = (Button) findViewById(R.id.Button);
if (activityButton != null) {
activityButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent startIntent = new Intent(MainActivity.this, SecondaryActivity.class);
startIntent.putExtra("com.example.owner.MESSAGE", "Hello SecondaryActivity");
startActivity(startIntent);
}
});
}
}
}
Secondary Activity
package com.example.owner.hour2application;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class SecondaryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondary);
Intent intent = getIntent();
String message = intent.getStringExtra("com.example.owner.MESSAGE");
TextView messageTextView = (TextView) findViewById(R.id.message);
if (messageTextView != null) {
messageTextView.setText(message);
}
}
}
Thanks guys sorry I posted the wrong main activity. The issue was in string.xml the string name was wrong. Thanks!

Fullscreen VideoView in landscape mode

I wish to make VideoView into full screen in landscape mode. I tried this. It shows a margin from left and right. I want to know how I can make the VideoView fullscreen.
My .xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="#+id/videoViewN"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
You may add theme to the activity in manifest file:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
And for VideoView in xml, change
android:layout_height="wrap_content"
to
android:layout_height="fill_parent"
This will help you achieve fullscreen in video view. Hope it helps.
adding below codes before setContentView works for me in onCreate function. I hope it helps.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Full Screen Landscape Video
AndroidManifext.xml (Setting the orientation)
<activity
android:name=".Video1"
android:screenOrientation="landscape" />
Video1.xml Code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Video1">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</VideoView>
Video1.java Code :
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;
public class Video1 extends AppCompatActivity {
private VideoView videoView;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video1);
videoView = findViewById(R.id.videoView);
String fullScreen = getIntent().getStringExtra("fullScreenInd");
if("y".equals(fullScreen)){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
}
Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.YOUR_VIDEO_NAME);
videoView.setVideoURI(videoUri);
mediaController = new FullScreenMediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
}
}
FullScreenMediaControler.java Code :
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.MediaController;
public class FullScreenMediaController extends MediaController {
private ImageButton fullScreen;
private String isFullScreen;
public FullScreenMediaController(Context context) {
super(context);
}
#Override
public void setAnchorView(View view) {
super.setAnchorView(view);
//image button for full screen to be added to media controller
fullScreen = new ImageButton (super.getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
params.rightMargin = 80;
addView(fullScreen, params);
//fullscreen indicator from intent
isFullScreen = ((Activity)getContext()).getIntent().
getStringExtra("fullScreenInd");
if("y".equals(isFullScreen)){
fullScreen.setImageResource(R.drawable.ic_fullscreen_exit);
}else{
fullScreen.setImageResource(R.drawable.ic_fullscreen);
}
//add listener to image button to handle full screen and exit full screen events
fullScreen.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(),Video1.class);
if("y".equals(isFullScreen)){
intent.putExtra("fullScreenInd", "");
}else{
intent.putExtra("fullScreenInd", "y");
}
((Activity)getContext()).startActivity(intent);
}
});
}
}

Input modify URL Webview?

users have an activity with an edittext and a button.
in the edittext they have to insert their login ID. and press go to display a other activity with webview loading the right site.
an example. this is the link i want users to visit . www.example.com/time/id=1/type=student
if sombody enters a 2 in the edittext it wil open the times for student id 2 and so on.
this is what i have.
LOGIN
package com.beter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
public class LoginActivity extends Activity {
Button go_btn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
go_btn = (Button) findViewById(R.id.go_btn);
go_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(LoginActivity.this, WebActivity.class);
LoginActivity.this.startActivity(myIntent);
}
});
}
and the layout
<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" >
<EditText
android:id="#+id/idfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="#string/id"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/go_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/idfield"
android:text="#string/login" />
The Webview Activity
package com.beter;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("http://roosters.gepro-osi.nl/roosters/rooster.php?wijzigingen=1&leerling=116277&type=Leerlingrooster&afdeling=12-13_OVERIG&school=905");
}
}
and again the layout
<?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" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
How do i make the user input. display the good webview. ?
First of all get a reference to your edittext in your Login Activity as
go_btn = (Button) findViewById(R.id.go_btn);
ed_txt = (EditText)findViewById(R.id.youredittextid);
The change your onClick to
public void onClick(View v) {
Intent myIntent = new Intent(LoginActivity.this, WebActivity.class);
myIntent.putExtra("id", ed_txt.getText());
LoginActivity.this.startActivity(myIntent);
}
Then retrive this id in your WebActivity onCreate as
String id = getIntent().getExtras().getString("id");
Then your url will be
String myURL = "www.example.com/time/id="+id+"/type=student";

Categories

Resources