If I run this code
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.settings",
"com.android.settings.Settings$NotificationAppListActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I get this
PICTURE 1
Instead,I want that the startActivity(intent) opens the activity that appears when I tap on the "Phone" view in the list
PICTURE 2
How can I get this ? Thanks
Use This..
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Or Edit your code line 2
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.settings",
"com.android.settings.Settings"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Because ComponentName method get 2 parameter 1. package name and 2. class name ComponentName(String pkg, String cls) first one, package name is ok but class name com.android.settings.Settings$NotificationAppListActivity that means you want to open Notification settings
try this way
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);
startActivity(intent);
Use this:
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
Related
the extras ( a notification text) doesn't get passed to the textView, (the text view appears empty), what's the problem?
here's the related code:
AlarmReceiver extends BroadcastReceiver :
https://textuploader.com/1j851
Notification Activity( that should show the text):
https://textuploader.com/1j85j
my main activity:
https://textuploader.com/1j8tr
please excuse me if I did any stupid mistakes, I'm new to programming
I guess this is your problem here. You pass the wrong value here. You make an object i but you are using intent object.
Intent i = new Intent(context,
NotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("message",x);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
So use like this below.
Intent i = new Intent(context,
NotificationActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK); //i
i.putExtra("message",x); //i
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
Does anyone know where can I find a full list of settings?
This is my code it works, the only problem I have I cannot find the line to bring up the google voice settings I'm looking for:
if (Build.VERSION.SDK_INT >= 14){
Intent intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}else {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
When I create a shortcut for my application, and when I want to delete shortcut with code, how should I do it? I try some method but not used.
The create shortcut code:
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test");
shortcut.putExtra("duplicate", false);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClass(this, SecondActivity.class);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);`
The delete shortcut code:
actionIntent.addCategory(Intent.CATEGORY_LAUNCHER);
actionIntent.setClass(this, SecondActivity.class);
Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "taotao");
intent.putExtra("duplicate", false);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
sendBroadcast(intent);`
I have created a "Button" in android studio to send emails. When I click it, it sends an email as intended, but does not then return to the "Home" activity.
You can use finish(); method, but it's not recommended.
See: How to finish current activity in Android
http://developer.android.com/guide/components/processes-and-threads.html#Threads
But, this is my suggestion, you should be able to after clicking the Button, then clear the activity and restart it(or you can do something like Gmail App and doing some stuffs after clicking):
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
Also you can use:
Intent m = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(m);
Or:
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
Intent intent = new Intent(context, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
How can I restart my application or MainActivity when the activity have:
android:launchMode="singleTop"
I have tried:
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
But because of singleTop this not working, there is an other way to do this?
I did my theme switcher like this:
Intent intent = getIntent();
finish();
startActivity(intent);
Basically, I'm calling finish() first, and I'm using the exact same intent this activity was started with. That seems to do the trick?
UPDATE: As pointed out by Ralf below, Activity.recreate() is the way to go in API 11 and beyond. This is preferable if you're in an API11+ environment. You can still check the current version and call the code snippet above if you're in API 10 or below. (Please don't forget to up-vote Ralf's answer!)
public void reload() {
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
or
private void restartFirstActivity()
{
Intent i = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage(getApplicationContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(i);
}
try to restart with this may this will help u
Intent i = cntxt.getPackageManager().getLaunchIntentForPackage(cntxt.getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addCategory(Intent.CATEGORY_HOME);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cntxt.startActivity(i);
Use this:
Intent finishIntent = new Intent( this,
activity_that_you_want_to_return.class);
finishIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(finishIntent);