Reputation: 1114
I have created a call receiver with abstract class
, by receiving call start recording of call and on call end stoping the recording, this flow is working perfect. What makes it difficult is after call ends, I want to open my form which is also working but it is creating problem some time that intent is not launching, is some one help me out whats going wrong that my activity
is not opening some times. Using following code to launch the activity
.
Intent dialogIntent = new Intent();
dialogIntent.setAction(Intent.ACTION_MAIN);
dialogIntent.addCategory(Intent.CATEGORY_LAUNCHER);
dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(context, CustomerEntery.class);
dialogIntent.setComponent(cn);
context.startActivity(dialogIntent);
Any help could be appreciated. Thanks in Advance
Upvotes: 0
Views: 136
Reputation: 1320
Replace your component line with this :
ComponentName cn = new ComponentName("The package name of the activity that you wish to launch","Its fully qualified class name");
Like
final ComponentName cn = new ComponentName(“com.android.settings”, “com.android.settings.fuelgauge.CustomerEntery”)
Just giving a try, hope this helps !
EDIT : Another way to achieve the same :
public boolean openActivity(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new ActivityNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}
Then :
openActivity(this, “com.android.settings.fuelgauge.CustomerEntery”);
Upvotes: 1