I built a chat application using firebase cloud messaging and firebase functions. But I have two problems currently.
1. When the app is in open and a new message comes in, the app will automatically move to the main activity of the application.
2. And secondly, I want notifications to be received only when it is in the background.
How do I achieve this?
Below is my onMessageReceived
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
showNotification(remoteMessage.getData().get("name"), (remoteMessage.getData().get("click_action")), remoteMessage.getData().get("title"));
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
}
}
private void showNotification(String name, String click_action, String title) {
Intent intent;
if (click_action.equals("Download")) {
intent = new Intent(this, Download.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (click_action.equals("Student_SystemsDevt")) {
intent = new Intent(this, Student_SystemsDevt.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
else {
intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(name)
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle())
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
My Manifest File
<application
android:name=".GTUCONLINE"
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:name=".LoginActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme" />
<activity android:name=".MainActivity">
</activity>
<activity
android:name=".ChoiceActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme" />
<activity
android:name=".WelcomeActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="#style/Base.Theme.AppCompat" />
<activity
android:name=".StudentSignUp"
android:screenOrientation="portrait"
android:theme="#style/MyTheme" />
<activity
android:name=".LecturerSignUp"
android:screenOrientation="portrait" />
<activity android:name=".ProgrammeActivity" />
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity
android:name=".TopicActivity"
android:theme="#style/MyTheme" />
<activity android:name=".MIS" />
<activity android:name=".GB" />
<activity android:name=".FIN" />
<activity android:name=".ENGINEERINGM" />
<activity android:name=".BDM" />
<activity android:name=".SCM" />
<activity android:name=".TE" />
<activity android:name=".TM" />
<activity android:name=".BET" />
<activity android:name=".ICT" />
<activity android:name=".T" />
<activity android:name=".IT" />
<activity android:name=".AM" />
<activity android:name=".OGM" />
<activity android:name=".I" />
<activity android:name=".PEF" />
<activity android:name=".QM" />
<activity android:name=".EPM" />
<activity android:name=".PM" />
<activity android:name=".HM" />
<activity android:name=".StudentsList">
<intent-filter>
<action android:name="StudentsList" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".LecturersList" />
<activity android:name=".AdminActivity" />
<activity
android:name=".ChatActivity"
android:parentActivityName=".StudentsList" />
<activity android:name=".LecturerMainActivity" />
<activity
android:name=".Download"
android:parentActivityName=".MIS">
<intent-filter>
<action android:name="Download" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MIS_Information"
android:parentActivityName=".MIS" />
<activity android:name=".Terms" />
<activity
android:name=".Admin_Login"
android:parentActivityName=".LoginActivity" />
<activity
android:name=".Manipulation"
android:parentActivityName=".Admin_Login" />
<activity android:name=".Admins" />
<activity
android:name=".SystemsDevt"
android:parentActivityName=".MIS" />
<activity
android:name=".SysGroupChat"
android:parentActivityName=".SystemsDevt" />
<activity
android:name=".EntSystems"
android:parentActivityName=".MIS" />
<activity android:name=".DownloadEnt">
<intent-filter>
<action android:name="DownloadEnt" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".student_mis" />
<activity
android:name=".Student_SystemsDevt"
android:parentActivityName=".student_mis">
<intent-filter>
<action android:name="Student_SystemsDevt" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Student_EntSys"
android:parentActivityName=".student_mis" />
<activity
android:name=".SystemsDevt_Add"
android:parentActivityName=".SystemsDevt" />
<activity android:name=".EntSystemsAdd" />
<activity android:name=".EntSystemsInfo" />
<activity
android:name=".DatabaseSystems"
android:parentActivityName=".MIS" />
<activity android:name=".DownloadDatabaseSys" />
<activity
android:name=".Student_DatabaseSystems"
android:parentActivityName=".student_mis" />
<activity android:name=".DatabaseInfo" />
<activity
android:name=".DatabaseAdd"
android:parentActivityName=".DatabaseSystems" />
<activity
android:name=".IntroToOil"
android:parentActivityName=".GB" />
<activity
android:name=".DownloadIntro"
android:parentActivityName=".IntroToOil" />
<activity
android:name=".IntroToOilInfo"
android:parentActivityName=".IntroToOil" />
<activity
android:name=".IntroToOilAdd"
android:parentActivityName=".IntroToOil" />
<activity android:name=".student_gb" />
<activity android:name=".StudentIntro" />
<activity android:name=".MIS_students_new"
android:parentActivityName=".SystemsDevt">
</activity>
</application>
1- Actually onMessageReceived is only triggered when your application is in foreground as described enter link description here. So if you don't override onMessageReceived, you will not receive push when your app is in foreground
2- According to fcm docs, when your app is in background, onMessageReceived is not triggered but
the data payload is delivered in the extras of the intent of your launcher Activity.
It explains why your push redirects to your main activity (your launcher).
So far, you can handle the redirection from the intent.
You can also specify the activity where it sould be redirected like enter link description here:
{
"to":"some_device_token",
"content_available": true,
"notification": {
"title": "hello",
"body": "test message",
"click_action": "OPEN_ACTIVITY_1"
},
"data": {
"extra":"juice"
}
}
don't forget intent filter for the desired activity:
<intent-filter>
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Also add Tasks permission in manifest.
private boolean isAppForeground() {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
final String packageName = getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
}
if(isAppForeground()){
// Handle notification silently without displaying in notification tray
}else{
// Do your regular stuff
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
showNotification(remoteMessage.getData().get("name"), (remoteMessage.getData().get("click_action")), remoteMessage.getData().get("title"));
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
}
}
Related
I am trying to add snap-kit in my application and I have integrated everything as their documentation. App successfully launched Snapchat app but it's not login it shows an error Something is wrong Here is my complete code and other implementation. This is the official documentation that I have followed https://kit.snapchat.com/docs/login-kit-android
MainActivity
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private static final String TAG = "MAIN_ACTIVITY";
String query = "{me{bitmoji{avatar},displayName}}";
String variables = null;
boolean isUserLoggedIn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
isUserLoggedIn = SnapLogin.isUserLoggedIn(this);
if (isUserLoggedIn)
binding.btnLogin.setText("Logout");
else
binding.btnLogin.setText("Logout");
binding.btnLogin.setOnClickListener(v -> {
SnapLogin.getAuthTokenManager(this).startTokenGrant();
binding.progress.setVisibility(View.VISIBLE);
});
SnapLogin.getLoginStateController(this).addOnLoginStateChangedListener(mLoginStateChangedListener);
SnapLogin.fetchUserData(this, query, null, new FetchUserDataCallback() {
#Override
public void onSuccess(#Nullable UserDataResponse userDataResponse) {
if (userDataResponse == null || userDataResponse.getData() == null) {
return;
}
MeData meData = userDataResponse.getData().getMe();
if (meData == null) {
return;
}
binding.txtName.setText(userDataResponse.getData().getMe().getDisplayName());
if (meData.getBitmojiData() != null) {
Glide.with(MainActivity.this)
.load(meData.getBitmojiData().getAvatar())
.into(binding.imgProfile);
}
}
#Override
public void onFailure(boolean isNetworkError, int statusCode) {
}
});
}
final LoginStateController.OnLoginStateChangedListener mLoginStateChangedListener =
new LoginStateController.OnLoginStateChangedListener() {
#Override
public void onLoginSucceeded() {
// Here you could update UI to show login success
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginSucceeded: ");
binding.btnLogin.setText("Logout");
}
#Override
public void onLoginFailed() {
// Here you could update UI to show login failure
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginFailed: ");
}
#Override
public void onLogout() {
// Here you could update UI to reflect logged out state
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLogout: ");
}
};
}
Manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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/Theme.SnapchatAndroidDemo">
<meta-data
android:name="com.snapchat.kit.sdk.clientId"
android:value="**********************" />
<meta-data
android:name="com.snapchat.kit.sdk.redirectUrl"
android:value="*********************" />
<meta-data
android:name="com.snapchat.kit.sdk.scopes"
android:resource="#array/snap_connect_scopes" />
<activity android:name=".ui.sign.SigninActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.intro.IntroActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.login.LoginActivity"
android:screenOrientation="nosensor"/>
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="nosensor"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.MainActivity"
android:screenOrientation="nosensor" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<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:host="lmk"
android:path="/oauth2"
android:scheme="lmk" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Dependencies
implementation([
'com.snapchat.kit.sdk:login:1.1.4',
'com.snapchat.kit.sdk:core:1.1.4'
])
You need to add these line in the application tag
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
Use like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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/Theme.SnapchatAndroidDemo">
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
<activity android:name=".intro.IntroActivity"/>
<activity android:name=".login.LoginActivity"/>
<activity
android:name=".splash.SplashActivity"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<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="lmk" android:host="lmk" android:path="/oauth2"/>
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Could you please check this for me?
I put the part of the code which I see is needed, if any other part I forgot please tell me.
I am following a tutorial from thenewboston and I stuck in here, the Intent SQLView won't run, and I don't know what is the problem.
P.S. I wanted to use debugger to get inside of it, but it seems it does not recognize any SQLView class.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.travis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Test"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Splash"
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=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Prefs"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.thenewboston.travis.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AboutUs"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.thenewboston.travis.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Email"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Camera"
android:label="Camera Application"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".OpenedClass"
android:label="Opened Class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Data"
android:label="Data"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".GFX"
android:label="Graphic"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".GFXSurface"
android:label="Graphic GFX"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SoundStuff"
android:label="Sound Stuff"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Slider"
android:label="Slider"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Tabs"
android:label="Tabs"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SimpleBrowser"
android:label="Simple Browser"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Flipper"
android:label="Simple Browser"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SharedPrefs"
android:label="Shared Preferences"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".InternalData"
android:label="InternalData"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".ExternalData"
android:label="ExternalData"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SQLiteExample"
android:label="SQLiteExample"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SQLView"
android:label="SQLiteView"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
Part that invoke SQLView:
try {
Intent i = new Intent("com.thenewboston.travis.SQLVIEW");
startActivity(i);
} catch (Exception e) {
e.printStackTrace();
Dialog d = new Dialog(this);
d.setTitle("Heck Yeah!");
TextView tvi = new TextView(this);
tvi.setText("we're fucked");
d.setContentView(tvi);
d.show();
}
And the SQLView:
package com.thenewboston.travis;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class SQLView extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlview);
TextView tv = (TextView) findViewById(R.id.tvSQLinfo);
HotOrNot info = new HotOrNot(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
}
}
In your Manifest change this
<activity
android:name=".SQLView"
android:label="SQLiteView"
android:screenOrientation="portrait" >
</activity>
to this:
<activity
android:name=".SQLView"
android:label="SQLiteView"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.thenewboston.travis.SQLVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You should have an intenet filter in you manifest, you probably forgot that. See if it works.
I have a Parse notification in my app. If I open my app. then it will receive the notification.
If I restart my phone. No notification will be received, until I open my app.
My question is:
How Can I initiate / run, my ParsePushBroadcastReceiver whenever the phone has been restarted. or how can I make this Receiver to be always running even if user close the app / kill the app ?
I though by adding android.intent.action.BOOT_COMPLETED would work. but it don't
Here is my manifest:
<activity
android:name=".SplashActivity"
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>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.my.app.core.MyParseReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.my.app" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher" />
My Class
....
public class MyParseReceiver extends ParsePushBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.i(TAG, "onReceive Called");
if (intent == null) {
Log.e(TAG, "Receiver intent null");
}
else {
// Parse push message and handle accordingly
Log.d(TAG, "Receiver intent data => " + intent.toString());
}
}//end onReceive
#Override
public void onPushOpen(Context context, Intent intent) {
...
I wouldn't recommend it but you could make an onBacKeyPressed() method and just make it look like the app has been killed.
manifest code for the built in search, using the searchview.
can anyone tell me please what is wrong with it?
the SearchableActivity is created in the scr -> presentation, and it is using an xml layout called search.xml. I am new to android and can't find out what is wrong with my code. when launching the search view typing a word and press on "Go" on the keyboard the debugger opens a ActivityThread.perfor.... and tells me source not found.
here is my hole manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myTV.Android"
android:versionCode="4"
android:versionName="1.12" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="12" />
<uses-feature
android:name="com.google.android.tv"
android:required="true" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:icon="#drawable/mytv"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<activity android:name="myTV.Presentation.Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="myTV.Presentation.Player" >
</activity>
<activity android:name="myTV.Presentation.VODCatalogGenre" >
</activity>
<activity android:name="myTV.Presentation.VODCatalog" >
</activity>
<activity android:name="myTV.Presentation.HomePage" >
</activity>
<activity android:name="myTV.Presentation.Programs" >
</activity>
<activity android:name="myTV.Presentation.Episodes" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
<activity android:name="myTV.Presentation.ChannelsListing" >
</activity>
<activity android:name="myTV.Presentation.Packages" >
</activity>
<activity android:name="myTV.Presentation.SpecialOfferContent" >
</activity>
<activity android:name="myTV.Presentation.linkedpage" >
</activity>
<activity android:name="myTV.Presentation.howtolinkdevice" >
</activity>
<activity android:name="myTV.Presentation.OnlineRegister" >
</activity>
<activity android:name="myTV.Presentation.SpecialOffer" >
</activity>
<activity android:name="myTV.Presentation.MyVOD" >
</activity>
<activity android:name="myTV.Presentation.SearchEpisodes" >
</activity>
<activity android:name=".Countries" />
<activity android:name=".Genres" />
<activity android:name=".WeeklyRecap" />
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
import myTV.Android.R;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class SearchableActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
public void doMySearch(String query){
//new Request().Search(query);
//new SearchEpisodes().Search(query);
Context context = getApplicationContext();
CharSequence text = query;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
Here is my searchable.xml:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/SearchHint" >
</searchable>
Try adding the below in your <intent-filter>.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
I think, your activity is not visible outside your Application.
Try android:exported="true".
On the app I am making, on the home menu screen that you get to after the splash screen, when you click one of the buttons, nothing happens. I don't know what the problem is?
Here is the src file, it implements View.OnClickListener:
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bPlay:
Intent ourIntentPlay = new Intent(PartyActivity.this, Play.class);
startActivity(ourIntentPlay);
break;
case R.id.bFacts:
Intent ourIntentFacts = new Intent(PartyActivity.this, Facts.class);
startActivity(ourIntentFacts);
break;
case R.id.bInfo:
Intent ourIntentInfo = new Intent(PartyActivity.this, Info.class);
startActivity(ourIntentInfo);
break;
case R.id.bHelp:
Intent ourIntentHelp = new Intent(PartyActivity.this, Help.class);
startActivity(ourIntentHelp);
break;
}
}
And here is the manifest, inside the application tags:
<activity
android:name=".Splash"
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=".PartyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.PARTYACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Info"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.INFO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Help"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.HELP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Thanks
Are you assigning a listener to your buttons? Do this in your onCreate() method:
findViewById(R.id.bPlay).setOnClickListener(clickListener);
If your activity implements OnClickListener, then clickListener will be this. Do this for all of your buttons.