Android - Bringing a background app to the front - java

This code does not bring my app to the front when the user has pressed the home button and the app has receded to the background. There are no error messages:
Log.d(TAG, "Bringing app to foreground");
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName componentName = new ComponentName(context.getPackageName(), context.getPackageName() + ".MainActivity");
launchIntent.setComponent(componentName);
try {
Log.d(TAG, "Launching intent");
context.startActivity(launchIntent);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
There are a number of questions asking the same thing and I seem to have tried all of the answers to no avail.
This is my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mystuff.myapp">
<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">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
</application>
<queries>
<package android:name="com.mystuff.myapp" />
</queries>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
</manifest>

Related

Android Automotive: Could not identify launch activity: Default Activity not found

I have just created my first Android Automotive project:
when I run AndroidAutoDemo.mobile module it works fine:
Unfortunately when I switch to AndroidAutoDemo.automotive module I get:
Could not identify launch activity: Default Activity not found
Error while Launching activity
Failed to launch an application on all devices
This is the Android Manifest file in AndroidAutoDemo.automotive module (left as default):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidautodemo">
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<application
android:allowBackup="true"
android:appCategory="audio"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AndroidAutoDemo" />
</manifest>
This is my mobile emulator:
How can I fix?
To run automotive app you need Automotive emulator and Automotive flavor with Manifest like below. Also there is no Automotive emulator provided by Google yet but you can get other open source emulator from like Polestar https://developer.polestar.com/sdk/polestar2-sys-img.xml
and Volvo https://developer.volvocars.com/sdk/volvo-sys-img.xml
You don't have to add new activity
if want to understand you can go through example source code
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app-samples/helloworld/
`
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.car.app.sample.helloworld"
android:versionCode="1"
android:versionName="1.0">
<!-- Various required feature settings for an automotive app. -->
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<uses-feature
android:name="android.software.car.templates_host"
android:required="true" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.landscape"
android:required="false" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:extractNativeLibs="false">
<meta-data
android:name="com.android.automotive"
android:resource="#xml/automotive_app_desc"
tools:ignore="MetadataTagInsideApplicationTag" />
<meta-data android:name="androidx.car.app.minCarApiLevel"
android:value="1"
tools:ignore="MetadataTagInsideApplicationTag" />
<service
android:name="androidx.car.app.sample.helloworld.common.HelloWorldService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
</intent-filter>
</service>
<activity
android:name="androidx.car.app.activity.CarAppActivity"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:exported="true"
android:launchMode="singleTask"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="distractionOptimized" android:value="true"/>
</activity>
</application>
</manifest>
`
Each Manifest file should include information about available activities and launcher activity. Launcher activity needs to be defined with some additional Intent filters, for example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.car">
<uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar">
<activity android:name="com.example.car.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Play Store says app is incompatible with phone tested on

The Play Store says that my app is incompatible with all the devices that I have, but that also includes the phone that I tested it on. Below is my Manifest file. I tested it on my Nexus 5X running Nougat, but the Play Store says that the app is incompatible with that phone of mine. Thanks a lot !
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.health4everyone.thejdeep.healthpal">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#####" />
<activity android:name="com.heath4everyone.thejdeep.healthpal.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.heath4everyone.thejdeep.healthpal.Home"></activity>
<activity android:name="com.heath4everyone.thejdeep.healthpal.Hospitals"></activity>
<activity
android:name="com.heath4everyone.thejdeep.healthpal.Restaurants"
android:label="Map">
</activity>
<activity android:name="com.heath4everyone.thejdeep.healthpal.ActivityTracker"></activity>
<activity android:name=".Settings" android:label="#string/app_name">
<intent-filter>
<action android:name="com.health4everyone.thejdeep.healthpal.Settings" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.heath4everyone.thejdeep.healthpal.SearchFoodByRestaurant"
android:label="Search Restaurant">
</activity>
</application>
</manifest>
Edit : Removed the API key :)

ReadExternalStorage permission is rejected, even after declaring it in the manifest

I know this is a really basic question but I'm stuck. I've declared that my app uses the read external storage permission, but my app is crashing when I try to perform an action that requires the permission. Here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-feature android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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>
</application>
Move the declarations to be children of the manifest, not the application:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<uses-feature android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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>

Error type 3: Activity Class {…} does not exist in Eclipse

Recently begun to experience this error when I try to run my android application using the Eclipse IDE, already looked at other solutions but found nothing to solve my problem. Below is the error log and my manifest file.
[2015-02-11 10:18:28 - PapiroSmart] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.prologica.papirosmart/.SplashScreenActivity }
[2015-02-11 10:18:28 - PapiroSmart] ActivityManager: Error type 3
[2015-02-11 10:18:28 - PapiroSmart] ActivityManager: Error: Activity class {com.prologica.papirosmart/com.prologica.papirosmart.SplashScreenActivity} does not exist.
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prologica.papirosmart"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- Accessing camera hardware -->
<uses-feature android:name="android.hardware.camera" />
<!-- Access permission to Android Folders -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Access permission to manage network conections -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<!-- Wi-Fi Permissions -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
</uses-permission>
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Papirosmart" >
<activity
android:name=".cliente.LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".cliente.MainActivity"
android:label="#string/app_name"
android:parentActivityName="cliente.LoginActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cliente.LoginActivity" />
</activity>
<activity
android:name=".cliente.ConfigActivity"
android:label="#string/app_name"
android:parentActivityName="cliente.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cliente.MainActivity" />
</activity>
<activity
android:name=".SplashScreenActivity"
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>
<activity
android:name=".cliente.FileChooserActivity"
android:label="#string/app_name"
android:parentActivityName="cliente.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cliente.MainActivity" />
</activity>
<activity android:name="eu.janmuller.android.simplecropimage.CropImage" />
<provider
android:name="InternalStorageContentProvider"
android:authorities="eu.janmuller.android.simplecropimage.CropImage"
android:exported="true" />
<receiver android:name=".app.ConnectionReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
<service android:name=".app.FileUploaderService" >
</service>
<receiver android:name=".app.FileUploaderReceiver" >
</receiver>
<service android:name=".app.SynchronizeService" >
</service>
</application>
</manifest>
it says com.prologica.papirosmart.SplashScreenActivity does not exists
so please use the specific packagename where SplashScreenActivity exists. supose if SplashScreenActivity is in package a.b.c. than use the package specific details with SplashScreenActivity .

the application on android cant run

why??
[2011-08-26 14:57:48 - Front] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=mpos.gui.ask/.Front } from null (pid=5918, uid=2000) requires null
my manifest
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mpos.gui.ask" android:versionCode="1" android:versionName="1.0">
<application android:debuggable="true" android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Front" 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="Login"></activity>
<activity android:name="FtpList"></activity>
<activity android:name="LoginMpos"></activity>
<activity android:name="MenuMpos"></activity>
<activity android:name="PilihCabang"></activity>
<activity android:name="FormTransaksi"></activity>
<activity android:name="SdhTrans"></activity>
<activity android:name="BuatTransaksi"></activity>
<activity android:name="LihatTrans"></activity>
<activity android:name="CekStok"></activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest
i'm pasive english :D
anyone can help
thanks be4
Are you accessing network status in your application too? If so I think you need to include permission for this too in your manifest.
In my case with flutter, I had a similar error that was solved by adding android:exported="true" to the main activity, so in your case it seems to be here
<activity android:name=".Front" android:label="#string/app_name" android:exported="true">

Categories