This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
How to restrict Android device to not open some specific site e.g.youtube, facebook
I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.
So I planned to kill the Android process if the user try to open it. I know that this code kills the process
android.os.Process.killProcess(pid);
but How can I get pid(process id) of process if it open youtube. The problem is to get process id which opens youtube.
I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.
Fortunately, malware authors have limited ability to do things like this.
So I planned to kill the Android browser process if the user try to open it.
Fortunately, this is impossible, at least on Android 2.1+.
I know that this code kills the process
Only if you have rights to kill that process. Fortunately, you do not have rights to kill that process.
If it is a webview they are opening the url in then you could use the public boolean shouldOverrideUrlLoading (WebView view, String url) this gives the host application a chance to take over the control when a new url is about to be loaded in the current WebView.
example:
WebViewClient yourWebClient = new WebViewClient()
{
// Override page
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// This line we let me load only pages inside Firstdroid Webpage
if ( url.contains("youtube") == true )
//Load new URL & override URL Link
return true;
// Return false to not override url loading.
return false;
}
};
Related
I have an Android app that serves content via webview. I've implemented a network connectivity alert so if my users are in a location where they can't get internet, I show a message. This takes place inside the onReceivedError method. It works as expected; if I disable all internet connections, I get a warning message. However, even when internet connection exists, the warning message still shows. If I minimize my app, open the native browser and visit 8-10 links, when I switch back to my app, I am given the network warning even though the device is connected to the network.
This only happens on one of my 6 test devices (my current phone, a Samsung Galaxy S10e. The problem does not occur on 5 different Android devices, both newer and older. I'm just looking for a way to ignore the warning when the app is in the background state. I've searched for an easy way to do this, but I haven't found anything simple that doesn't involve writing a new class.
How can I write a conditional statement to do nothing when the onReceivedError method is triggered while the app is in the background? Here is a portion of my code, along with what I would like to have happen:
#override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
// the part I need help with
if ("app in background"){
// do nothing
} else {
// this is where I have employed my notification, a snackbar
}
}
Thank you for your help!
I have an Android mobile application that works with the membership system.
There are links to other mobile applications and games in my application.
With Packet Manager, I can check whether the application in the link is installed on the phone. My goal is to check whether users have downloaded the game and mobile applications on the device by clicking the links in my application.
If they downloaded the application in the given link once (first time), they will earn 10 points. If they download the same application many times, they will be considered as one time.
I wanted to ask you that If users download an app more than once, how do I count it just one time?
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
public void go(View view) {
boolean installed = appInstalledOrNot("com.dousoftware.pubgtyolar");
//loaded
if (installed) {
Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
} else {
Intent viewIntent = new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?
id = com.dousoftware.pubgtyolar "));
startActivity(viewIntent); Toast.makeText(this, "Not Loaded", Toast.LENGTH_SHORT).show();
}
}
The short answer is: you can't.
There is no way to know, locally, on an Android device, how many times the user installed or uninstalled an app.
The long answer is that there may be some workarounds, each with its own advantages and disadvantages.
While your app is installed, you could register to ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REMOVED broadcasts.
These will be called every time the user installs or removes any app.
They have EXTRA_PACKAGE_NAME that contains the app package name.
This however, presents some problems:
This will only work while your app is installed and the user has opened your app at least once.
You will receive this broadcast for any app, and will have to filter the results yourself.
If the user clears data or uninstalls and reinstalls your app, you will lose count.
Another way, and how most apps do it, is by using a referral framework.
One example is Iron Source which will let you set up rewards for installing and using different apps.
If the other app is also yours, you can simply use Firebase.
Note however, that referral tracking compromises user privacy, so you have to be careful to comply with any local laws such as GDPR.
Also, using these frameworks may cost money.
If user click link
Check that user don't have this application
Redirect to store page.
Set in the config file that this link has been clicked
If user install application and Script triggers (eg on app opening) add points. Add points only if Link has been marked as clicked.
Mark the link in config file as used to not give more points from the same app.
You can store this data on your server to avoid eg uninstalling abuse
Simply save somewhere information that link has been used
So, this is a rather unusual question, and I can't find anything else anywhere which has been helpful on how to do this, or if its even possible to do so.
I'm working on a game server wrote in java, and I'm trying to get the users default web browser to open to a specific link, when a command is typed into the chat box and sent to the server.
The current Issue I have is, when a user issues the command, it opens the browser on the host system, and not the players system.
I haven't been able to try any other methods, as I am unable to find any information regarding my specific situation!
#CommandHandlerMethod(accessLevel = EAccessLevel.USER)
public static Object[] vote(final Player player, final String... params) {
try {
Desktop desktop = java.awt.Desktop.getDesktop();
URI oURL = new URI("www.example.com");
desktop.browse(oURL);
} catch (Exception e) {
e.printStackTrace();
}
return AbstractCommandHandler.getAcceptResult("");
}
What I was hoping for via this code, was to open the web browser on the players system to allow them to view a specific webpage, but this has not been the case, and opens it on the server host system.
I am implementing FB in one of my app.I am using jar 0.8.25. Its working fine on all simulators from 5 to 7.1.And for devices works only for OS 5 and 6 but not working on device 7 and 7.1.For OS 7 after log in success it remains on FB page it doesn't redirect back. and when i press back button, i get error encountered unable to refresh access token with try again button.
When analyzing on console it never finds access token single time for OS 7.while for 5 and 6 its working perfectly.
Please tell what may cause the issue.
Thanks,
This isn't a solution to your specific problem. I mentioned in the comments that I'm using an interface. So I'm posting here as its too much for the comment section. It is also not the COMPLETE solution, you will need to handle the flow and expired tokens, this is just to show you the logic of how I did this.
For my interface I open a browserfield to the Oauth url:
https://www.facebook.com/dialog/oauth?client_id=<APP_ID>&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions
And I add a listener to this browser to listen for the redirects after login. Once you have the access token, you should persist it and close the browserfield.
private class OAuthScreen extends MainScreen
{
BrowserField browser_field;
LoadingDialog loading_dialog;
public OAuthScreen(final Command task)
{
super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);
BrowserFieldConfig browserConfig = new BrowserFieldConfig();
browserConfig.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth()));
browser_field = new BrowserField(browserConfig);
browser_field.addListener(new BrowserFieldListener()
{
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception
{
int index = browserField.getDocumentUrl().indexOf("#access_token=");
if (index == -1)
{
super.documentCreated(browserField, scriptEngine, document);
}
else
{
access_token = browserField.getDocumentUrl().substring(index + "#access_token=".length(), browserField.getDocumentUrl().indexOf("&"));
PersistentObject store = PersistentStore.getPersistentObject(STORE_KEY);
FacebookTokens store_tokens = new FacebookTokens();
store_tokens.access_token = access_token;
store.setContents(store_tokens);
store.commit();
if (task != null) task.execute();
OAuthScreen.this.close();
}
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception
{
super.documentLoaded(browserField, document);
loading_dialog.close();
}
});
// whatever loading dialog you want, this sometimes takes a while to open
loading_dialog = LoadingDialog.push(loading_field);
add(browser_field);
browser_field.requestContent("https://www.facebook.com/dialog/oauth?client_id="+APP_ID+"&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions");
}
}
The callback task is just for if I want to perform a call directly after login.
Now just perform API calls as you need them. API methods here https://developers.facebook.com/docs/graph-api/reference/v2.0/
Methods that require the access token, should have it appended to the url such as, https://graph.facebook.com/me/feed?access_token=" + access_token
Be aware that clearing your access token won't clear the token stored in the browser field. And will mean that you can't login next time (because the browser is still logged in).
So if you want to logout you need to open this link in a browserfield before clearing your local access token "https://www.facebook.com/logout.php?next=http://www.facebook.com/connect/login_success.html&access_token=" + access_token
Clearing the cookies of the browser should suffice, but I haven't found a way to do this.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Open Facebook page from Android app?
Does the Android Facebook app have Intents that other apps can use to start the Facebook app and goto a specific page?
For example, when someone clicks a certain button in my app, I want them to be taken to Facebook to a specific company's public Facebook page. Starting a web browser activity for this is easy, but more than likely the user is not logged in the browser etc...
I was thinking it would be nice if I could instead use an Intent (if one exists...) to start up the Facebook app and take the user to the specific page in the app. That way the user is already logged in and can interact with the page, Like it, etc...
Does an Intent like this exist? If so, where would I find more information on it? I've been looking through Facebook's developer documentation but I'm not seeing anything about this.
Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
Copy your id
Use this method:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id_here>"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
}
}
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.