SEARCH_ACTION doesn't work in my SearchActivity - android

I'm trying to implement google's new feature, Search using a specific app. I want to ask something to google now in this format "search for ... on myApp" but it doesn't work.
This is the only code google recommend to add in AndroidManifest:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
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=".SearchActivity"
android:label="#string/title_activity_search"
android:parentActivityName=".MainActivity" >
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
StartActivity:
import com.google.android.gms.actions.SearchIntents;
public class SearchActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
Intent i = getIntent();
if (SearchIntents.ACTION_SEARCH.equals(i.getAction())) {
String query = i.getStringExtra(SearchManager.QUERY);
Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
}
}
My app isn't signed! Could it be this the problem?

Without knowing the rest of your code, I'd suggest reading up on Creating a Search Interface.
At first glance, it looks like you're missing the
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
after your IntentFilter.
ETA: I don't think having the Toast show in onCreate is going to give you any information. Searching will have to happen after the onCreate method. Breakpoint through your onCreate and see what the value of "i" (your Intent) is.

Related

Android 12 Device Owner Provisioning

I have an application, that can be successfully setup as Device Owner on devices up to Android 12 via QR code from JSON below:
{
"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME":
"package.CustomDeviceAdminReceiver",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM":
"actual_checksum",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION":
"https://Site/APK_Link",
"android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED": true
}
App contains declared receiver:
<receiver
android:name=".deviceadmin.CustomDeviceAdminReceiver"
android:description="#string/app_name"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/enterprise_device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE" />
</intent-filter>
</receiver>
For Android 12 (as described here https://source.android.com/devices/tech/admin/provision) I added 2 activities:
<activity
android:name=".deviceadmin.AdminPolicyComplianceActivity"
android:screenOrientation="portrait"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<action android:name="android.app.action.ADMIN_POLICY_COMPLIANCE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".deviceadmin.ProvisioningModeActivity"
android:screenOrientation="portrait"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<action android:name="android.app.action.GET_PROVISIONING_MODE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
1st one:
public class ProvisioningModeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_provisioning_mode);
Intent intent = getIntent();
int provisioningMode = 1;
List<Integer> allowedProvisioningModes = intent.getIntegerArrayListExtra(DevicePolicyManager.EXTRA_PROVISIONING_ALLOWED_PROVISIONING_MODES);
if (allowedProvisioningModes.contains(DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE))
provisioningMode = DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE;
else if (allowedProvisioningModes.contains(DevicePolicyManager.PROVISIONING_MODE_MANAGED_PROFILE))
provisioningMode = DevicePolicyManager.PROVISIONING_MODE_MANAGED_PROFILE;
Intent resultIntent = new Intent();
resultIntent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_MODE, provisioningMode);
setResult(RESULT_OK, resultIntent);
finish();
}
}
and 2nd one (almost empty):
public class AdminPolicyComplianceActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_policy_compliance);
setResult(RESULT_OK);
finish();
}
}
but I got error while enrollment: "Can't setup device. Can't use the admin app. It's missing components or corrupted".
Can somebody find that I missed please?
From Android 12 we are supposed to have components exported safely. Since your activities ProvisioningModeActivity and AdminPolicyComplianceActivity uses intent filter, we have to set the exported flag.
<activity
android:name=".deviceadmin.AdminPolicyComplianceActivity"
android:screenOrientation="portrait"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
<intent-filter>
<action
android:name="android.app.action.ADMIN_POLICY_COMPLIANCE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".deviceadmin.ProvisioningModeActivity"
android:screenOrientation="portrait"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
<intent-filter>
<action android:name="android.app.action.GET_PROVISIONING_MODE"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This way firmware will be able to recognize the activity and launch it.
Also, regarding android:testOnly="false", this flag must be false if you are going to do QR code provisioning. If its true then, you will be able to remove admin via android settings.
#faz the reason this code doesn't work on Android 11 and below is because the ProvisioningModeActivity intent is not fired with an extra integer array of DevicePolicyManager.EXTRA_PROVISIONING_ALLOWED_PROVISIONING_MODES. To overcome this add a null check to the allowedProvisioningModes

App is installed twice

I have a shoppinglist App coded in Android-Studios. My app does have a splash screen. When I install the app, it is installed twice. When I uninstall one, the other one uninstalls too. I tried to delete the first intent filter on splashscreen, but then I did not have a splash screen anymore. I want my splashscreen to be remain. How to solve that? My manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projects.buylist">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The app is only one.
You have simply two activities (and then 2 icons) that can work as launcher.
If you don't want, you have to remove this part in one Activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<category android:name="android.intent.category.LAUNCHER" /> this is telling android you want the activity to be visible from the app launcher. To solve it, remove the intent-filter from MainActivity.
Delete your main intent in XML and create something like this, which will run splashscreen and then open your MainActivity
public class SplashsScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(SplashsScreen.this, MainActivity.class);
SplashsScreen.this.startActivity(mainIntent);
SplashsScreen.this.finish();
}
}, 1500); // 1500 ms = 1.5 s
}
}

No activity found to handle Intent/no launcher activity found manifest file issue

Here's the problem guys, first i tried to run my application with Launch default activity as launch action (Run Configurations --> Android --> Launch action), the logcat kept telling me that it can't find the launcher activity and the application wouldn't even start, problem is i defined my launcher activity in the manifest file, but it's like it's not reading it at all.
So i tried to launch the splash activity by specifically telling it to run it through run configurations, it did launch but during the transition to the next activity it crashed again, the logcat says no activity found to handle intent, which again, I defined the way I did in other applications and worked alright there. Plase help it's a nightmare.
Here's the code for the MainActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer = new Thread()
{
public void run(){
try{
sleep(6000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="totaltrainer.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutPlace"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutPlace" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutHome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutHome" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutGym"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutGym" />
</intent-filter>
</activity>
</application>
</manifest>
use "totaltrainer.com.WORKOUTGYM" and so on
and below use this
<category android:name="android.intent.category.DEFAULT" />
Problem 1
logcat kept telling me that it can't find the launcher activity and
the application wouldn't even start
In your Manifest file, change below
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What happens when you define this Action and Category ?
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in the system's app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.
These two must be paired together in order for the activity to appear in the app launcher.
Problem 2
the logcat says no activity found to handle intent
Your Manifest declaration seems fine.
In your activity class, change
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
as
Intent openStarting = new Intent();
openStarting.setAction("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);

Android activity added but never triggering onCreate()

I've added a new Activity, but the Toast message doesn't ever appear. It's not Toast specific though, it doesn't reach this class in general.
public class SecondActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// This should appear
Toast(..., "Inside of SecondActivity onCreate", ...).show();
}
...
My AndroidManifest looks like this,
<application
...
<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=".SecondActivity" ></activity>
</application>
you never call show() on your Toast
the launcher activity is MainActivity, but the Toast is inside SecondActivity. Did you add the logic to launch SecondActivity?
Edit:
From your Manifest I can read
<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>
So, when you execute your Application, the first activity launched will be MainActivity. Inside it you need to launch SecondActivity. For instance inside MainActivity's onCreate you could have something like:
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

Why is my app launching the wrong activities?

I have play buttons on custom popups and they are taking me to the wrong activity and im not sure why. The activity its launching is not even in the onclick method.
Button playit = (Button) dialog.findViewById(R.id.playDetourDialog);
playit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("go to pyramid");
Intent i = new Intent(getApplicationContext(), PyramidGamePlay.class);
startActivity(i);
dialog.dismiss();
}
});
manifest:
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Main"
android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="GamePlayRegular"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="WorldSelect"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="OptionsPage"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="World"></activity>
<activity android:name="GameEndPage" android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="PyramidGamePlay"></activity>
</application>
Use like this
<activity android:name="PyramidGameplay">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It's hard to know without more information. Have you defined your activity in your AndroidManifest.xml? What info does logcat print when you tap the playit button?
It would also be good to use the android.util.log package for logging, rather than using System.out.println.

Categories

Resources