using Activity in Android Widget - java

i need an Activity in my Widget Provider. Is there any way to realize that?
The problem is: I want to write a little Facebook Widget but: The Facebook API needs an Activity in the Authorize Function... without this function i get an Facebook Error. Xan i call a Object in my Activity from this Widget ? Or, can i "share" this Object global?
Facebook facebook = new Facebook("X X X");
facebook.authorize(this, new String[] {}, new DialogListener() { });
https://developers.facebook.com/docs/reference/androidsdk/authentication/

Facebook api requires an activity to display a dialog with authentication, you should create an Activity in your app and start it to display auth dialog.

Related

Finish multiple activities on an authentication flow android

So I have an app that has authentication on it
here is the flow:
LoginPage -> Register -> RegisterConfirmation -> OTP Code -> EmailVerification -> Homepage
I want that if the user is already on OTP Code or Email Verification and he pressed the back button, the user will get straight to Homepage because he already got the AccessToken since RegisterConfirmation.
Here's the flow I want to look like:
How can I possible does this, I've already done some research but all I got is only how to finish only one activity (parent)?
Don't let the user go to OTP Code and check in registerconfirmation activity if the user already obtained his token access.
If you try to start an activity say A and you are in the current activity say D, you can use this with your intent :
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
To clear top activities (B,C,D)
EDIT:
You can keep the current instance of your activity using
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
When the user presses Back button do the below on onBackPressed() method. This might solve your problem. What it does is it clears the previous task and creates a new task
with the only activity in stack.
val intent = Intent(this,HomeActivity::class.java).apply{
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
startActivity(intent)
finish()

Receive URL intent in Splash Screen and load the URL in WebView

I'm having a slightly different purpose, but, I think I'm putting it wrong as no one from multiple forums is able to answer it. The original question is here: Pass URL data from AppLink to WebView
Basically, suppose I'm creating a web browser app with a splash screen and I want to accept the URL intents from other apps, receive them in my splash screen, pass them on to my WebView activity and load it there, how can I do that?
For example, if a user has my app installed, and he/she taps https://www.google.com/ as a link in some app, how can I load the URL in my app after showing my splash screen? I think, the intent receiver will be in the splash screen activity, and the WebView is in another activity. So, basically, I want to receive the URL in my splash screen activity and then, pass it on to my WebView. How to achieve this?
I think what youre trying to do is to recieve data from other apps
That way, you can recieve data in a Splash Screen Activity and then show it in a Web View Activity
You can do this through putExtra method.
You can use intents, which are messages sent between activities. In an intent you can put all sort of data, String, int, etc.
In your case, in Splash Screen(say SplashActivity), before going to next activity(say MainActivity), you need to store a String message this way :
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("message", message);
startActivity(intent);
In MainActivity, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Then you can use message variable as url.:
Hope this helps !

android - resuming from last visited page in my app

I have login page (activity) which is my first activity (landing page) of the app.
Only after user gives correct username and password, the app allow you go to other pages to work with.
Now my question is, now the user is at the fourth page and he is working on it, And he minimize the app and use other app like messaging etc..
so when he come back to click my app icon again, my app starts from the first landing page, which is the login page,
how can I make my app to resume from the fourth page?
Android 4.4.4, Kit Kat, Samsung
Regards,
Nay TK
Add this in android manifest of loginActivity,
android:launchMode="singleTask"
more on android:launchMode
An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:
"standard"
"singleTop"
"singleTask"
"singleInstance"
The system creates the activity at the root of a new task and routes
the intent to it. However, if an instance of the activity already
exists, the system routes the intent to existing instance through a
call to its onNewIntent() method, rather than creating a new one.
go through official link for more detail
You can make your fourth activity as your launch activity.
In the Resume of your Activity, you check if the user is logged in. If not, you start your Login activity.

Always open android webview Login dialog when user logged out from my app

I've integrated Facebook in my app and the user can login, share and post things. I've implemented a logout also.
Here is my problem: when user wants to log in, the Facebook SDK checks whether the native app is present or not.
If the native Facebook app is not installed in the user's device then it will open a webview dialog like the image below (First image).
If the user has the Facebook app, then my app directly asks him/her for permissions without opening the loginUI (Second Image)
.
I want to show the Facebook loginUI always.
Each time the user wants to login.
Please help me.
Yeah i did it....
if anyone in future face this situation this solution may help them
For opening webdialog during login with facebook
If you are using facebook login button, we need to set the property called as "SessionLoginBehaviour" then write the below code.
loginButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
refer this
You can check it if facebook installed using this method :
private boolean isFacebookExist(){
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.facebook.katana", 0 );
return true;
} catch( PackageManager.NameNotFoundException e ){
return false;
}
}

Stop Android Process from Web App

I'm working on an Android app that communicates with a web app and I need help figuring out how to stop a process in the Android app from the web app. I need to allow the user of the web app to simply click a button which will stop a process within the android app. Any ideas on how to do this? Any help would be great. Thanks!
Edit: I'm using JavaScript for my web app.
Actually you can call native Android code from WebView. This means that you can call whatever function you want of your Adnroid app from within your Web app. See this:
Calling native code from within web view:
When creating the web view add javascript interface (basically java class whose methods will be exposed to be called via javascript in the web view).
JavaScriptInterface jsInterface = new JavaScriptInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(jsInterface, "JSInterface");
The definition of the javascript interface class itself (this is examplary class I took from another answer of mine and opens video in native intent)
public class JavaScriptInterface {
private Activity activity;
public JavaScriptInterface(Activity activiy) {
this.activity = activiy;
}
public void startVideo(String videoAddress){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp"); // The Mime type can actually be determined from the file
activity.startActivity(intent);
}
}
Now if yo want to call this code form the html of the page you provide the following method:
<script>
function playVideo(video){
window.JSInterface.startVideo(video);
}
</script>
So you need to add the appropriate method to JSInterface and call the code from within the Web App.

Categories