Removing an Android Shortcut from Home screen - java

I am trying to remove a shortcut from the home screen that my app has already added. I have tried the methods in these links but I can't figure out how to adapt their solutions to my code. I dont have a rooted device so I cant find the URI.
https://codinggeekorg.wordpress.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/
Trying to UNINSTALL_SHORTCUT but shortcut won't go away
Android: Remove app shortcut from home screen
Here is where I create the shortcut:
protected void ShortcutCreatorActivity(String number, String message, String name) {
Intent shortcutIntent = new Intent(getApplicationContext(), ShortCutActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("number", number);
shortcutIntent.putExtra("message", message);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abezukor.autosms" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RelativeLayoutActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".ListViewActivity"
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=".ShortCutActivity"
android:label="AutoSms">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks for your help in advance.

Related

Arrange activities in android studio

I have a splash screen in my project it opens first with intent filter. After that it opens the main activity. But i created new activity that should be opened next to splash screen how to do that?
I have created three activities for example splash screen, main activity, login screen, Splash screen first opens next to that i need to open the login screen next only main activity.
xml code
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_main"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_main_round"
android:supportsRtl="true"
android:theme="#style/Theme.WeatherApp">
<activity
android:name=".SplashScreen"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".HomeActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
</application>
There are few ways to achieve this. This is one of my way.
First, at your AndroidManifest.xml, make sure you make your SplashActivity becomes your launcher. Then, at the onCreate method for your SplashActivity, do some delay, checking some stuff, is this user login or not. Last, go to next activity.
<activity
android:name="company.com.ui.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
new Handler().postDelayed(
new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this, Login.class);
finish();
}
},
4000);

How to start an app on boot completed in android?

I have tried every solution on the internet. But none of them worked for me. Could you check where I am doing wrong?
Maybe it no longer works in higher Api.
Here is my broadcastReceiver class :
public class ReceiverToStartAnApp extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "Home Task 3 Version ", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(context, CameraRecorderActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hometaskversion3">
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HomeTaskVersion3">
<activity
android:name=".ui.CameraRecorderActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.RecorderService" />
<receiver
android:name=".receiver.ReceiverToStartAnApp"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
First of all, apps that have never been started in some way do not receive system broadcasts. So you need some activity of your app to start before you receive ACTION_BOOT_COMPLETED.
Second, as noted in the comments, it is no longer allowed to start an activity from a receiver unless some conditions are met. The preferred way to do it is to show a notification with a pending intent for the activity you need to start. This approach will be less intrusive for the user.

When I start a new activity, my app crashes. How to fix that?

private void userIsLoggedIn() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null){
Intent i = new Intent(getApplicationContext(), MainPageActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
}
That is the code that should change the activity ^^
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tylerwilliams.openmessagingv2">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Spectrum Messenger"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainPageActivity" />
<activity
android:name=".LoginActivitys"
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=".FindUserActivity" />
</application>
</manifest>
That is my manifest code, I have tried to change it but whenever I do I either make more problems or it won't work. I am pretty sure its me just being a noob and that I have got something in the manifest wrong.

Intent activity class not working

hey guys so im having a problem when trying to run the emulator of my application on android studio. this is the error im getting:
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dre.appli/com.example.dre.appli_app.LoginActivity }
Error type 3
Error: Activity class {com.example.dre.appli/com.example.dre.appli_app.LoginActivity} does not exist.
ive tried everything that people have suggested to no avail. here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wheretas.appli_app">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
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=".CreateAccount"
android:label="#string/title_activity_create_account"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="app.createaccount" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I suppose your LoginActivity has a package com.example.dre.appli_app.LoginActivity
But your manifest's package is different:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wheretas.appli_app">
...
Try to set it com.example.dre.appli_app

How to open a new instance of the same application?

I'd like to open a new instance of the same application, much like chrome used to by default when opening a new tab (See this)
here's what I've tried so far:
PackageManager pm = getContext().getPackageManager();
Intent launcher = pm.getLaunchIntentForPackage("my.package.name");
launcher.setAction(Intent.ACTION_VIEW);
launcher.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launcher.setData(Uri.parse(result.getExtra()));
getContext().startActivity(launcher);
it does start a new activity and also loads the correct data, but it doesn't open a new screen.
how would I achieve this?
HERE'S MY MANIFEST FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.depa.browsing.stack">
<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-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:fullBackupContent="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="stateAlwaysHidden"
android:targetActivity=".MainActivity"
android:icon="#mipmap/ic_launcher">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".About"/>
<activity android:name=".Donate"/>
<activity android:name=".Settings"/>
<activity android:name=".GPL"/>
<activity android:name=".History"/>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>

Categories

Resources