Hi I've create a simple link browser, but I lost last update to open external URL.
This is the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.browser">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.test.browser.WebViewActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<data android:scheme="http" />
<data android:scheme="https" />
<action android:name="android.intent.action.PICK" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
And this my simple WebViewActivity.java
public class WebViewActivity extends AppCompatActivity {
public static Activity controller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
controller = this;
mURL = "";
if (getIntent().getData() != null) {
setWebViewAndLoadURL(mURL);
} else {
this.finishAffinity();
}
}
}
The method 'setWebViewAndLoadURL' is not important because the action.VIEW not working.
Do you have any solutions?
I suggest to use the WebView layout in your activity which is more simple.
`<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />`
in your WebViewActivity modify the code with :
String url = "https://www.google.com";
setContentView(R.layout.your_layout);
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
Tnx to all.
I found solution.
In XML I must add this to intent-filter:
<data android:scheme="http" android:host="*"/>
<data android:scheme="https" android:host="*"/>
And in Activity I must add intent URL:
mURL = "";
if (getIntent().getData() != null) {
mURL = getIntent().getData().toString();
setWebViewAndLoadURL(mURL);
}
Related
I tried to create this small custom browser, but I have a small problem, when I click on a link, it opens it quietly, but first I open a blank page, as if it were a new instance of the activity. In fact when I try to go back from the open link, I go about the activity with the blank page. It does not change page, but the activity. What am I doing wrong?
ACTIVITY:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "";
if (getIntent().getData() != null) {
setContentView(R.layout.activity_main);
url = getIntent().getData().toString();
WebView wv = (WebView) findViewById(R.id.webView);
WebSettings settings = wv.getSettings();
settings.setDomStorageEnabled(true);
wv.clearCache(true);
wv.clearHistory();
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
wv.setWebChromeClient(new WebChromeClient());
wv.loadUrl(url);
}
}
}
LAYOUT:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="com.andrea.webviewsample.MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andrea.webviewsample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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/AppTheme"
android:launchMode="singleTask">
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="*" />
<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.APP_BROWSER" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
THIS IS THE RESULT:
Solution found!
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "";
if (getIntent().getData() != null) {
WebView wv = new WebView(this);
url = getIntent().getData().toString();
WebSettings settings = wv.getSettings();
settings.setDomStorageEnabled(true);
wv.clearCache(true);
wv.clearHistory();
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
wv.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
wv.loadUrl(url);
setContentView(wv);
}
}
well i have one problem with parse, but i can´t know why it crashes, i explain it.
Im working with parse, and works ok, but then with no reason, sometimes, when i turn off the mobile or go out of the wifi´s range, the app crashes. i think all its ok, cause i can recieve parse´s notifications with no problem.... well need some help here
The app its a webview
public class MainActivity extends Activity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.activity_main);
Parse.initialize(getApplicationContext(), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveEventually();
this.myWebView = (WebView) this.findViewById(R.id.web);
myWebView.getSettings().setJavaScriptEnabled(true);
//iniciamos javascript
myWebView.addJavascriptInterface(new WebAppInterface(this),"Android");
//webviewclient para websettings
WebSettings websettings= myWebView.getSettings();
websettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("http://www.aaaaa.com/);
}
#Override
public void onBackPressed(){
if(this.myWebView.canGoBack())
this.myWebView.goBack();
else
super.onBackPressed();
}
private class MyWebViewClient extends WebViewClient{
#SuppressWarnings("unused")
private long loadTime;
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (Uri.parse(url).getHost().equals("www.aaaaa.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
public class ParseBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "received " + intent.getAction());
PushService.startServiceIfRequired(context);
}
}
}
}
and then the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jor.dietd"
android:versionCode="3"
android:versionName="1.2" >
<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.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.jor.dietd.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.jor.xxxxxx.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jor.xxxxx.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.jor.xxxx" />
</intent-filter>
</receiver>
</application>
</manifest>
I know there are similar question in statckoverflow, but they just do NOT work for me.
Broadcast receiver(staticly registe via manifest.xml) can NOT receive package_remove event after installing on device (without running main activity)
But the receiver works if main activity is running.
To register broadcastreceiver staticly in AndroidManifest.xml as followings
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceivertesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.broadcastreceivertesting.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.broadcastreceivertesting.PackageBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
PackageBroadcastReceiver as a receiver are like following:
public class PackageBroadcastReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
final String action = intent.getAction();
if (Intent.ACTION_PACKAGE_REMOVED.equals(action))
{
File file = new File("/storage/sdcard0/zzz/yyy");
if (file.exists())
{
file.delete();
}
boolean createDir = new File("/storage/sdcard0/zzz/").mkdirs();
Log.d("XXX", "XXXX createDir=" + createDir);
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
Do I miss something ?
Try changing this...
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
to this...
<intent-filter>
<action android:value="android.intent.action.PACKAGE_REMOVED" />
<scheme android:value="package" />
For more information, see this link on receiving package broadcast intents...
https://groups.google.com/forum/#!topic/android-developers/aX5-fMbdPR8
When user want to uninstall app from android device, I want user uninstall button click event for that application.
I am getting event of application is removed from device, but I want to show pop-up before application is removed. I am trying to achieve same like doing in 'App Lock' application.
Here is my code to get application removed event through broadcast receiver. But I am totally blank about uninstall button click or before pop-up click. Please guide me in right direction.
Thanks in advance.
public class MainActivity extends Activity {
CustomBroadcastReceiver mApplicationsReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mApplicationsReceiver=new CustomBroadcastReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
filter.addAction(Intent.ACTION_PACKAGE_VERIFIED);
filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
filter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH);
filter.addAction(Intent.ACTION_DELETE);
filter.addAction(Intent.ACTION_DEFAULT);
filter.addDataScheme("package");
registerReceiver(mApplicationsReceiver, filter);
}
}
public class CustomBroadcastReceiver extends BroadcastReceiver {
/**
* This method captures the event when a package has been removed
*/
#Override
public void onReceive(Context context, Intent intent)
{
System.out.println("Hello from CustomBroadcastReceiver");
if (intent != null) {
String action = intent.getAction();
System.out.println("L1123 : "+action);
if (action.equals(intent.ACTION_PACKAGE_REMOVED)) {
//Log the event capture in the log file ...
System.out.println("The package has been removed");
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bits.uninstallappdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <receiver android:name=".CustomBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
</intent-filter>
</receiver> -->
</application>
</manifest>
Please try to get the top activity in the task via ActivityManager, and check if it is the uninstall activity.
Core code:
ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
String packageName = topActivity.getPackageName();
String className = topActivity.getClassName();
Log.v(TAG, "packageName" + packageName);
Log.v(TAG, "className" + className);
if ("com.android.packageinstaller".equals(packageName)
&& "com.android.packageinstaller.UninstallerActivity".equals(className)) {
//Do anything you want here
}
The following permissions which you are using are granted to system apps only. Make sure you have rooted device to allow such permissions.
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
First off, I know this has been asked before and I have gone through many many posts regarding this. Unfortunately, my case seems to be a bit different. Most of the posts advised to remove the permission statement from application tag. This, unfortunately, does not help my situation, as I do not have permissions inside the application tag. I would very much appreciate any assistance.
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jonasSoftware.blueharvest"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.jonasSoftware.blueharvest.LoginActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.jonasSoftware.blueharvest.ChargeActivity"
android:label="#string/title_activity_charge" >
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jonasSoftware.blueharvest.HomeActivity"
android:label="Home" >
</activity>
<activity
android:name="com.jonasSoftware.blueharvest.ConfigActivity"
android:label="Config" >
</activity>
<activity
android:name="com.jonasSoftware.blueharvest.SettingsActivity"
android:label="Settings" >
</activity>
<activity android:name=".WebServiceDemo" android:label="WebServiceDemo"/>
<activity android:name=".UploadActivity"/>
<activity android:name=".TransferActivity"/>
<activity android:name=".ReceivePO"/>
<activity android:name=".LoginActivity"/>
</application>
</manifest>
The LoginActivity, if needed, is below. For testing purposes, it just starts the HomeActivity intent, with the majority of the code being commented out.
public class LoginActivity extends Activity {
// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_USERNAME = "username";
private static String KEY_CREATED_AT = "created_at";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
setTitle("onas Scanner Login");
final Button loginBtn = (Button) findViewById(R.id.btnLogin);
final EditText loginUsername = (EditText) findViewById(R.id.loginUsername);
final EditText loginPassword = (EditText) findViewById(R.id.loginPassword);
final TextView loginErrorMsg = (TextView) findViewById(R.id.login_error);
loginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//do stuff
String username = loginUsername.getText().toString();
String password = loginPassword.getText().toString();
Intent homeActivity = new Intent(getApplicationContext(), HomeActivity.class);
homeActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeActivity);
}
});
}
}
If any other information is required, please let me know.
So as I was about to post this, I realized what my mistake was. Looking through the Manifest again I noticed something interesting. The application did not originally have the LoginActivity. When I added the LoginActivity, the following line was added to the Manifest.
<activity android:name=".LoginActivity"/>
I did not know this at the time and so just edited the original launcher activity, as seen below.
<activity
android:name="com.jonasSoftware.blueharvest.LoginActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the android:name= line had originally been "com.jonasSoftware.blueharvest.HomeActivity". So when I removed the extra line from the Manifest, everything started working again.
I hope this helps someone.
Brad.