I am trying to start activities from a class that extends Application. I am able to do that using FLAG_NEW_ACTIVITY_TASK as flag intent that is creating the activity.
Let me illustrate a scenario that I am trying to implement.
There are two users USER1 and USER2. If USER1 presses a button(HOLD) a new activity is created on USER2's device. This launching of new activity on USER2's device is done by the class that extends Application. Then when USER1 presses a button(UNHOLD) I want the USER2's device to bring up the previous activity. I am able to bring up the previous activity but it is being recreated because of the FLAG_NEW_ACTIVITY_TASK flag, I want that activity to be resumed instead of being recreated.
I am stuck here, I did search on google but could not understand what should I do. Please Help.
Manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".MyApplication" >
<service android:name=".PortSipService"></service>
<service android:name=".Ringback"></service>
<service android:name=".LocationService"></service>
<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>
<activity android:name=".SaveContacts" android:label="#string/app_name"> </activity>
<activity android:name=".IncomingCall" android:label="#string/app_name"> </activity>
<activity android:name=".ContactActivity" android:label="#string/app_name"></activity>
<activity android:name=".CallConnected" android:label="#string/app_name"></activity>
<activity android:name=".OutgoingCall" android:label="#string/app_name"></activity>
<activity android:name=".MusicPlayer" android:label="#string/app_name"></activity>
</application>
This is when on hold,
Intent music = new Intent(getApplicationContext(),MusicPlayer.class); music.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(music);
This is when unhold pressed,
Intent connect = new Intent(getApplicationContext(),CallConnected.class);
connect.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(connect);
I do not want this callconnected activity to be recreated, But it is because of the intent flag.
You may try use Activity instead Context like this:
Intent music = new Intent(MainActivity.this,MusicPlayer.class);
music.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainActivity.this.startActivity(music);
Related
I'm loading my website in webview. And inside that website also contains two buttons "Take photo" and "Upload". In the browser on the phone it works perfectly. As in, the "Take photo" button lets you take a photo, and the "Upload" button lets you upload a photo. But inside my app, it doesn't seem to do anything. And I know this has something to do with permissions. Here's my code:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<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" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_favicon_1144_rounded"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.Test2">
<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>
I haven't changed my MainActivity.kt at all, but if you want, I can edit this question and add it in.
This is not possible. From android app webview, you can not get access to device's permissions.
I am new to Android Development and I am developing an application to scan barcode using google vision API. In the application, I have three screens Splash Screen, Main Screen with two fragments (Scan & History) and Scanned Result. From the scan fragment, I am opening an activity called "ScannedResult" as soon as application scanned the barcode to show the result.
Now the problem is when I run the application from the Android Studio to the device.
[Scenario# 0] (From the Main activity screen app stopping that is the correct case)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, STOP the application from the Android Studio.
Application stopped
[Scenario# 1] (But from ScannedResult activity app stops and start again why?)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, Scan a Bar or QR Code then open ScannedResult (activity).
Now, STOP the application from the Android Studio.
Application stopped and show Black Screen
Application STARTED again and shows the Main Screen (Why it is starting again? I want to stop the application in this case).
Here I am suspecting something is wrong. Ideally, it must be stopped. Please help to identify where I am making mistake in the application.
Here is the Manifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.powertools.barcodescan">
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".CreatePaypalUrl"
android:parentActivityName=".MainActivity"></activity>
<activity
android:name=".CreateVcardForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateLocationForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWifiForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEventForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateSmsForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEmailForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTelephoneForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWebsiteForm"
android:parentActivityName=".MainActivity" />
<activity android:name=".Main2Activity" />
<activity
android:name=".GenerateQrCode"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTextForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".ScannedResult"
android:parentActivityName=".MainActivity" />
<activity
android:name=".SplashScreen"
android:label="#string/app_name" android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
</application>
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
Scan.java file
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
#Override
public void release() {
}
#Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if (qrCodes.size() > 0) {
if (isScanned == false) {
barcodeDetector.release();
isScanned = true;
String dataType = getBarcodeType(qrCodes.valueAt(0));
String dataValue = qrCodes.valueAt(0).displayValue;
String rawValue = qrCodes.valueAt(0).rawValue;
Intent intentScannedResult = new Intent(getActivity(), ScannedResult.class);
intentScannedResult.putExtra("barcode_raw_value", rawValue);
intentScannedResult.putExtra("barcode_value", dataValue);
intentScannedResult.putExtra("barcode_type", dataType);
intentScannedResult.putExtra("is_scanner", "1");
startActivity(intentScannedResult);
}
}
}
});
I followed all the steps from both the articles mentioned below
https://hackernoon.com/react-native-deep-linking-for-ios-and-android-d33abfba7ef3
https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e
After the app gets installed on my phone, I tried opening the app from the browser by giving the URL as peopleapp://people/1 format. Instead of opening the app, the browser opens Google search to search for the above.
I Used this application to open my Application by using my App Link(https://play.google.com/store/apps/details?id=com.manoj.dlt&hl=en_US) it's working.
But how to open the application from browser or from another application Using my App Link ?
Anyone has idea, how to solve this issue ?
Here is my Total AndroidManifest Code`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="whizzard" android:host="article" />
</intent-filter>
</activity>
</application>
`
My Link is whizzard://article
As per google docs:
The functionality has changed slightly in Chrome for Android, versions 25 and later. It is no longer possible to launch an Android app by setting an iframe's src attribute. For example, navigating an iframe to a URI with a custom scheme such as paulsawesomeapp:// will not work even if the user has the appropriate app installed. Instead, you should implement a user gesture to launch the app via a custom scheme, or use the “intent:”.
You can read more about how intents work here. However, the tutorial you followed, for deeplinking will work on other browsers which are not chrome or chrome based.
I am happily receiving notifications when app is in background and foreground but when app is killed, I am not receiving notifications in some phones (like Xiaomi model phones eg mi3, etc.)
GCM message 0:1434141725194227%03b66390f9fd7ecd
broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg= (has extras) }
Although I am getting notifications in other phones like nexus, samsung, others.
Did anyone also had similar problem?
Can someone explain me where I am wrong.
Here is my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<package_name>">
<permission android:name="<package_name>.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="<package_name>.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<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_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="android.net.wifi.STATE_CHANGE"/>
<application
android:name="<package_name>.ApplicationSingleton"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="<package_name>.ui.activity.ReferralActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="<package_name>.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<package_name>" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="<package_name>"/>
</intent-filter>
</receiver>
<service android:name="<package_name>.gcm.GcmIntentService" />
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Autostart probably the best MIUI feature that doesn’t come enabled by default, but should.
What does autostart do? It basically starts the apps you select when the phone starts, so you never miss any notifications or updates.
To enable autostart for your apps, follow the steps below:
Tap on the Security app from the app screen.
You will not find this if you enter from the Settings menu, you have to tap directly on the app icon.
Open Security App:
Once in the Security app, tap on Permissions.
Tap on Autostart
Toggle the apps you want to enable Autostart for
Reboot your phone.
Now you are all set up with autostart!
I'm experiencing a trouble on my app, my backButton quit the application.
My application is a SyncService, everything seems to be great in the Manifest, i check for one day with no response...
I already check if the launchmode change something, i test the 4 and nothing append...
If someone can have a look on the manifest, it would be great :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smile.android.ldapsync" android:versionCode="12" android:versionName="1.5">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:enabled="true" android:persistent="true">
<service android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticationService" android:exported="true" android:debuggable="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="#xml/authenticator" />
</service>
<service android:name="com.smile.android.ldapsync.syncadapter.SyncService" android:exported="true" android:debuggable="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter" android:resource="#xml/syncadapter" />
</service>
<activity android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticatorActivity" android:label="#string/ui_activity_title" android:excludeFromRecents="true">
android:excludeFromRecents="true"
<!--
No intent-filter here! This activity is only ever launched by
someone who explicitly knows the class name
-->
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
</manifest>
Thank you ;)
Did you tried overriding onBackPressed ?
#Override
public void onBackPressed() {
return;
}
if you press back button while on the "main" activity (the first one you launched aka the bottom of your activity stack) the OS understand this as "the user is done and won't be back anytime soon" opposed as "home" button which is understood as "maybe the user wants to check something else before resuming the app"
So, if you DO NOT want your app to "terminate" (an android app terminates only when the OS kills it, otherwise it will lurk in memory until recalled) you need to override the back button pressed callback
public void onBackPressed()
which the api doc describes as:
"Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want."
You might just ignore the event and absorb it like timo schloesser suggested or you can do whatever is most appropriated (like, launching another activity or killing services before leaving the screen)
EDIT: you might also want to check the "moveTaskToBack" method inherited from Activity class. I have never used it but it might be useful to your problem.