Need Help on a Facebook app code in order to show Live Videos - facebook

I need some assistance on my final capstone design project for my university. My question is, How can I develop an android studio code (Kotlin) for Facebook in order to show Live videos from a "Client" website?
I already have a working code that shows the client's website, just need to be able to show his Live videos. This work is to finish my bachelor's degree in ELECTRICAL engineering, so no previous experience in programming apart from the C++ classes that I took 3 years ago.
This is the code i have now,
class FacebookActivity : AppCompatActivity() {
private lateinit var callbackManager: CallbackManager
/**
* This creates the page for Facebook login
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_facebook)
// Initialize the Facebook Login callback manager
callbackManager = CallbackManager.Factory.create()
// Register a callback for the Facebook Login button
btnLogin.registerCallback(callbackManager, object : FacebookCallback<LoginResult> {
// If the Facebook Login is successful
override fun onSuccess(loginResult: LoginResult) {
Log.d("FacebookActivity", "Facebook token: " + loginResult.accessToken.token)
startFacebookPage()
}
// If the Facebook Login is cancelled
override fun onCancel() {
Log.d("FacebookActivity", "Facebook Login cancelled.")
}
// If there is an error during the Facebook Login
override fun onError(error: FacebookException) {
Log.d("FacebookActivity", "Facebook Login error: " + error.message)
}
})
// Check if the user is already logged in to Facebook
if (AccessToken.isCurrentAccessTokenActive()) {
startFacebookPage()
} else {
// Log in the user with read permissions if they are not already logged in
LoginManager.getInstance().logInWithReadPermissions(this, listOf("public_profile"))
}
}
// Start the Facebook page
private fun startFacebookPage() {
val facebookIntent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://www.facebook.com/radiodiosmedijonotecalles")
}
startActivity(facebookIntent)
}
/**
* This allows to go "back"
*/
override fun onSupportNavigateUp(): Boolean {
onBackPressedDispatcher.onBackPressed()
return true
}
}
And the Manifest;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher2"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher2_round"
android:supportsRtl="true"
android:theme="#style/Theme.RadioDiosMeDijoNoTeCalles"
tools:targetApi="33">
<activity
android:name=".ClientActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".AboutThisAppActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".FacebookActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="true" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="#string/facebook_client_token" />
<activity
android:name=".ZenoRadioActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".YouTubeActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".LinksActivity"
android:exported="false" />
<activity
android:name=".TwitchActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".DonationsActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any and all Help will be greatly appreciated!

Related

Deep Link for Android with .Net Maui error - Unable to instantiate activity ComponentInfo MainActivity

I'm trying to get deep links to work for my maui android app but when I click to open the link with the app I get this error:
Java.Lang.RuntimeException: 'Unable to instantiate activity ComponentInfo{app.mydomain/MyApp.Client.MAUI.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class "MyApp.Client.MAUI.MainActivity"
on path: DexPathList[[zip file "/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk"],
nativeLibraryDirectories=[/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/lib/arm64,
/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk!/lib/arm64-v8a, /system/lib64,
/system_ext/lib64]]'
My MainActivity.cs looks like this
namespace MyApp.Client.MAUI
{
[Activity(Theme = "#style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "https", DataHost = "mydomain.app", DataPathPattern = "/.*", AutoVerify = true)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
protected override void OnResume()
{
base.OnResume();
Platform.OnResume(this);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
var data = intent.DataString;
if (intent.Action != Intent.ActionView) return;
if (string.IsNullOrWhiteSpace(data)) return;
var path = data.Replace(#"https://mydomain.app", "");
//todo - handle path
StartActivity(typeof(MainActivity));
}
}
The intent filter in the AndroidManifest.xml is like so:
<activity android:name="MyApp.Client.MAUI.MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="mydomain.app" android:pathPattern="/.*" />
</intent-filter>
</activity>
I could reproduce your problem.
And I can resolve this problem by adding tag <application> inside of AndroidManifest.xml.
You can refer to the full code of AndroidManifest.xml on my side:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.INTERNET" />
      <application android:allowBackup="true" android:supportsRtl="true" android:theme="#style/AppTheme" android:name="android.app.Application" android:debuggable="true" android:extractNativeLibs="true">
            <activity android:name="MauiBlazorApp.MainActivity" android:exported="true">
                  <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
                        <data android:scheme="https" android:host="mydomain.app" android:pathPattern="/.*" />
                  </intent-filter>
            </activity>
            
      </application>
</manifest>
Note: Remember to change the value of android:name(YourAppName) of your activity to yours.
<application android:name="YourAppName.MainActivity">

Received BOOT broadcast but cannot start Service

I want to make my application's background service start when the device is on, So I make a BOOT receiver to start my service.
Here is My Mainifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
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/Theme.MyApplication">
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is THE boot receiver:
package com.example.myapplication
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
Log.d("NEWTAG","BOOT is ON!!!!!")
val startIntent = Intent(context,MyService::class.java)
context.startService(startIntent)
Log.d("NEWTAG","SERVICE IS ON!!!!!")
}
}
This is My Service:
package com.example.myapplication
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
class MyService : Service() {
override fun onBind(intent: Intent): IBinder {
TODO("Return the communication channel to the service.")
}
override fun onCreate() {
super.onCreate()
Log.d("NEWTAG","Service OnCreate!!!!!")
}
override fun onDestroy() {
Log.d("NEWTAG","Service OnCreate!!!!!")
super.onDestroy()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d("NEWTAG","Service OnCreate!!!!!")
return START_STICKY
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
Log.d("NEWTAG","Service OnCreate!!!!!")
}
}
I can get the
BOOT is ON!!!!!
from the receiver, But I cannot get the
Service OnCreate!!!!!
And the serivce's OnCreate() and OnStartCommand() did not run either.
Can anybody do me a favour?
Your BroadcastReceiver might not be starting after boot. Please check.

Android Facebook Login button XML error

I want to create a test project works 'facebook login'.
I made with reference to the developers site and blog equal, But I met with an error message on xml.
[error massage]
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebooktest.zoit.facebooktest/com.facebooktest.zoit.facebooktest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.facebook.login.widget.LoginButton
[xml]
<com.facebook.login.widget.LoginButton
android:id="#+id/facebook_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp" />
[Manifest]
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebooktest.zoit.facebooktest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</manifest>
[MainActivity]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
facebookLoginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {...
...
public void onActivityResult(...
void geHashKey(){...
void geHashKey(){ ...
public void onResume(){ ...
public void onPause(){...
Do you know what's wrong? please help.
I know!
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_main);
"setContentView(R.layout.activity_main);"
I succeeded to move the this code below to Facebook code.

Revmob Unity : Banner ads not clickable

I am developing a game which required to show Revmob Banner ads.
I can successfully show banner ads, but can't not click on it. It's media id is into testing mode.
My code for it is below.
private RevMob rev mob;
void Awake() {
revmob = RevMob.Start(REVMOB_APP_IDS, "RevMob");
}
void Start() {
revmob.CreateBanner(RevMob.Position.BOTTOM);
revmob.ShowBanner(RevMob.Position.BOTTOM);
}
Please help me.
Try adding the following line in the AndroidManifest.xml file within the activity tags for UnityPlayerNativeActivity
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
Example
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false" android:largeHeap="true">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="#string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>

import com.google.ads.*; doesn't have AdManager

I'm really stuck here, trying to set a banner with ads-admob to my android app. I have done all the layout settings in the main.xml, also worked in the manifest file with the permissions, tried both XML and JAVA methods to show the ads and trying to make it work but I always get "could not get currentAdManager" from logcat in Eclipse. The application also crashes here, but works just fine without the admob settings. My admob SDK is GoogleAdMobAdsSdk-6.0.1.jar and I'm developing using phonegap .
I noticed that the command "import com.google.ads.*;" doesn't have the "AdManager" because when I insert individually the "import com.google.ads.AdManager;", I receive the error message "The import com.google.ads.AdManager cannot be resolved". My files:
My JAVA:
> package what.car.notes;
>
> import android.os.Bundle;
> import org.apache.cordova.*;
> import com.google.ads.AdView;
> import com.google.ads.AdManager; **- ERROR APEARS HERE**
> import com.google.ads.*;
>
> public class Cargeous21forActivity extends DroidGap {
> /** Called when the activity is first created. */
> #Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> super.loadUrl("file:///android_asset/www/index.html");
> setContentView(R.layout.main);
>
> dView adView = (AdView)this.findViewById(R.id.AdView);
> adView.loadAd(new AdRequest());
> }
> }
My LAYOUT file (main.xml):
> <?xml version="1.0" encoding="utf-8"?>
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
> xmlns:myapp="http://schemas.android.com/apk/res/what.car.notes"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> android:orientation="vertical">
>
> <com.admob.android.ads.AdView
> android:id="#+id/AdView"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> myapp:backgroundColor="#000000"
> myapp:primaryTextColor="#FFFFFF"
> myapp:secondaryTextColor="#CCCCCC"
> />
>
> </LinearLayout>
My MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="what.car.notes"
android:versionCode="4"
android:versionName="1.3" >
<uses-sdk android:minSdkVersion="7" />
<uses-library
android:name="com.google.ads.AdManager" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:value="i've put my correct id here" android:name="ADMOB_PUBLISHER_ID" />
<activity android:name="com.admob.android.ads.AdMobActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|keyboardHidden"
android:value="SQLite-NDK" />
<!-- Track Market installs -->
<receiver android:name="com.admob.android.ads.analytics.InstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
And finally, the attrs.xml:
> <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable
> name="com.admob.android.ads.AdView"> <attr name="backgroundColor"
> format="color" /> <attr name="primaryTextColor" format="color" />
> <attr name="secondaryTextColor" format="color" /> <attr
> name="keywords" format="string" /> <attr name="refreshInterval"
> format="integer" /> </declare-styleable> </resources>
Does anyone have already been through such a thing?
Please read the getting started guide for the Google AdMob SDK on Android. The example from which you got that code is from an old Google ads SDK before the Google AdMob Ads SDK rewrite.
Issues I can see on first pass:
You're manifest's activity definition is incorrect. See this page for the correct AdActivity activity definition.
You don't need attrs.xml. The SDK includes these attributes now.
I don't think the publisher id can be a meta-vale. You must specify the publisher id in your AdView XML definition.
Your AdView XML definition needs to have an adSize.
The new Google AdMob SDK doesn't have a com.google.ads.AdManager class.
Thanks Eric! Your answer helped me a lot to find the right code. The final code looks like this:
JAVA:
import android.os.Bundle;
import org.apache.cordova.*;
import android.app.Activity;
import android.os.Handler;
import com.google.ads.*;
import android.widget.*;
import android.widget.LinearLayout;
public class myactActivity extends DroidGap {
private static final String MY_AD_UNIT_ID = "a14fd7e04e46295";
private AdView adView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
//
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout layout = super.root; // this is the only change from the sample
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<com.google.ads.GoogleAdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
EVerthing worked since then... BUT! YEs, there is a but... 2 days later, with the incredible amount of $0,00 and 150 ads solicitacion, admob/google canceled my account!! I had heard their method are weird and remove developers for no reason at all and, with $0,00 and 150 views they cut me off of their program. Good part: I found some other ad services better than admob, but the minus side is that I'll have to figure out the code all over again...
Thanks anyway Eric!