Facebook login error in Flutter - Please follow our document to upgrade to new APIs to avoid overriding onActivityResult() - flutter

Error: You're calling logging in Facebook with an activity supports androidx activity result APIs. Please follow our document to upgrade to new APIs to avoid overriding onActivityResult().
I do not have an MainActivity.java file. Instead I have MainActivity.kt
Here my MainActivity.kt:
package com.***.app
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(flutterEngine:
FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
And here my AndroidManifest.xml
<application
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:label="***"
android:icon="#mipmap/ic_launcher">
<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="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
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="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
...
This is, how I call the flutter_facebook_auth package login method
flutter_facebook_auth: ^4.4.1+1
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
final LoginResult result = await FacebookAuth.instance
.login(permissions: ['name', 'email']);
I followed the steps described here:
https://facebook.meedu.app/docs/4.x.x/android
https://developers.facebook.com/docs/facebook-login/android/?locale=en
https://developers.facebook.com/apps/569466344883647/fb-login/quickstart/

Solved the problem by using flutter_login_facebook instead of flutter_facebook_auth. There where no further changes necessary then that
Thanks to #Bellrampion for the suggestion.
From:
final LoginResult result = await FacebookAuth.instance
.login(permissions: ['name', 'email']);
to
import 'package:flutter_login_facebook/flutter_login_facebook.dart';
class FacebookSignInApi {
// Create an instance of FacebookLogin
static final fb = FacebookLogin();
static login() async {
// Log in
final res = await fb.logIn(permissions: [
FacebookPermission.publicProfile,
FacebookPermission.email,
]);
}
}

Related

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

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!

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.

cannot find symbol public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine)

I am getting this error while trying to register plugin in MainActivity.java file
Error log
: error: cannot find symbol
public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
^
MainActivity.java
package com.orsac.bluis;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity { #Override public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine); }
}
In AndroidManifest.xml file, getting Unresolved class error in android:name=".UniappApplication" and android:name=".MainActivity"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.orsac.bluis">
<application
android:name=".UniappApplication" // Here
android:label="BLUIS"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity" // Here
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
Things I Tried
Flutter clean
Flutter run
Invalidate caches and restart
You should import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
1- Update targetSdkVersion and compileSdkVersion to the latest and equal version in build.gradle(app level) under android section
2- Import these libraries in MainActivity
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin;

How can I create a project in Android Studio to function default SMS app

Continuation of the previous query, see: SMS Receiver for AND API 19 and higher
I need to make the application run in the background and I could have it after installing the set as a default as shown here: http://android-developers.blogspot.cz/2013/10/getting-your-sms-apps-ready-for-kitkat.html
So I asked how to create a project to display a list of the "Super Duper SMS," which finally set as default.
The whole program must running as a service, without the need any screen for basic functions Receive SMS and should be registered in the core android
Thanks for any advice
I am tried with this code it help me...
manifests.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsmsapp">
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/smsicon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.newsmsapp.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity android:name="com.example.newsmsapp.ComposeSMS">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</activity>
<receiver
android:name="com.example.newsmsapp.SMSReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<activity
android:name="com.example.newsmsapp.NotificationView"
android:label="#string/title_activity_notification_view"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<receiver android:name="com.example.newsmsapp.MMSReceiver" android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER"/>
<data android:mimeType="application/vnd.wap.mms-message"/>
</intent-filter>
</receiver>
<service android:name="com.example.newsmsapp.HandlessSMSSendService"
android:exported="true"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</service>
</application>
then create 4 file for smsReader,mmsReader,ComposeSMS,HeadlessSMSservice
smsReader.java
public class SMSReceiver extends BroadcastReceiver {
Notification notification;//=new Notification(R.drawable.icon,"New Message",System.currentTimeMillis());
NotificationManager notificationmaneger;
String SMSmsg;
public SMSReceiver() {
}
public static final String SMS_BUNDLE = "pdus";
#Override
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
builder.setAutoCancel(true);
// builder.setTicker("this is ticker text");
builder.setContentTitle("New Messge");
builder.setContentText(SMSmsg);
builder.setSmallIcon(R.drawable.smsicon);
builder.setColor(context.getResources().getColor(R.color.colorAccent));
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
// builder.setSubText("You have pending tax"); //API level 16
//builder.setNumber(100);
builder.build();
}
SMSmsg=smsMessageStr;
}
}
mmsReader.java
public class MMSReceiver extends BroadcastReceiver
{
public MMSReceiver()
{
}
#Override
public void onReceive(Context context, Intent intent) {
}
}
ComposeSMS.java
public class ComposeSMS extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
}
}
HeadlessSMSservices.java
public class HandlessSMSSendService extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
if u want to see SMS then add listview in composeSMS.java and bind received data from sms table to listview adapter.