Android Studio: cannot resolve getApplication() [duplicate] - java

This question already has answers here:
How to get application object into fragment class
(6 answers)
Closed 5 years ago.
I am trying to access the global variable declared in AndroidManifest.xml in UARTlogfragment.java but there is an error in the use of getApplication() i.e. "cannot resolve".
I am posting my Androidmanifest.xml and the UARTlogfragment.java here.
The AndroidManifest.xml is:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="no.nordicsemi.android.LOG" />
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
<!-- 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:name=".ToolboxApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".SplashscreenActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.no.nordicsemi.type.app" />
<data android:mimeType="application/vnd.no.nordicsemi.type.address" />
</intent-filter>
</activity>
<!-- Template plugin activities -->
<!-- Remember to add your plug-in Activities to the Android Manifest file. -->
<!-- Plug-in activities -->
<activity
android:name=".FeaturesActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/AppTheme.TranslucentStatusBar" />
<activity
android:name=".uart.UARTActivity"
android:icon="#drawable/ic_uart_feature"
android:label="#string/uart_feature_title"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="no.nordicsemi.android.nrftoolbox.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".proximity.ProximityService"
android:label="#string/proximity_feature_title" />
<service
android:name=".dfu.DfuService"
android:exported="true"
android:label="#string/dfu_service_title">
<intent-filter>
<action android:name="no.nordicsemi.android.action.DFU_UPLOAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<activity
android:name=".dfu.DfuInitiatorActivity"
android:label="#string/dfu_service_title"
android:noHistory="true"
android:theme="#style/AppTheme.Translucent">
<intent-filter>
<action android:name="no.nordicsemi.android.action.DFU_UPLOAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".cgms.CGMService"
android:label="#string/cgms_feature_title" />
<service
android:name=".rsc.RSCService"
android:label="#string/rsc_feature_title" />
<service
android:name=".csc.CSCService"
android:label="#string/csc_feature_title" />
<service
android:name=".hts.HTSService"
android:label="#string/hts_feature_title" />
<service
android:name=".uart.UARTService"
android:label="#string/uart_feature_title" />
<service android:name=".wearable.MainWearableListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:pathPrefix="/nrftoolbox"
android:scheme="wear" />
</intent-filter>
</service>
<provider
android:name=".uart.UARTLocalLogContentProvider"
android:authorities="no.nordicsemi.android.nrftoolbox.uart.log"
android:exported="true" />
<activity
android:name=".Register_Page"
android:label="#string/title_activity_register__page" />
<activity android:name=".View_Profile" />
<activity android:name=".Profile" />
<activity android:name=".Wallet_Page" />
<activity android:name=".confirm_booking" />
<activity android:name=".LoginActivity" />
<activity android:name=".Add_Amount" />
<activity android:name=".last_step_book"></activity>
</application>
The UARTlogfragment.java(where I am trying to access the global variable) is :
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_feature_uart_log, container, false);
mydb = new no.nordicsemi.android.nrftoolbox.myDbAdapter(getContext());
String s = ((ToolboxApplication) this.getApplication()).getSomeVariable();
Cursor rs = mydb.getData(1);
rs.moveToFirst();
String nam = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_NAME));
String phon = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_PHONE));
String emai = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_EMAIL));
String cit = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_CITY));
String gend = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_GENDER));
String pas = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_PASS));
String dobb = rs.getString(rs.getColumnIndex(no.nordicsemi.android.nrftoolbox.myDbAdapter.CONTACTS_COLUMN_DOB));
if (!rs.isClosed()) {
rs.close();
}
final EditText field = mField = view.findViewById(R.id.field);
mField.setText(nam+" "+emai+" "+phon+" "+gend+" "+cit);
field.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEND) {
onSendClicked();
return true;
}
return false;
});
final Button sendButton = mSendButton = view.findViewById(R.id.action_send);
sendButton.setOnClickListener(v -> onSendClicked());
return view;
}
What is the error ?? And why cannot it resolve getApplication()??

Change
String s = ((ToolboxApplication) this.getApplication()).getSomeVariable();
to
String s = ((ToolboxApplication) getActivity().getApplication()).getSomeVariable();

As you are trying yo use application context from fragment you can not use getApplication() because isn't method of Fragment class
So you first have to use the getActivity() which will return a Fragment Activity to which the fragment is currently associated with.
to sumup in your code,
instead of this.getApplication() you have to use getActivity.getApplication()

Related

Fix cannot find symbol mInterstitialAd = new InterstitialAd(this); symbol: variable mInterstitialAd location: class Ads [duplicate]

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 1 year ago.
I'm integrating admob ads in my application with java but getting this
cannot find symbol mInterstitialAd = new InterstitialAd(this); symbol:
variable mInterstitialAd location: class Ads
. Please check the util/Ads.java & AndroidManifest.xml file and help me to fix it. I'm not able to fix this.
util/Ads.java
package com.indiapps.documentscanner.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.android.gms.ads.InterstitialAd;
public class Ads {
public static void showAds(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long currentTimeMillis = System.currentTimeMillis();
long lastTime = sharedPreferences.getLong("lastTime", 0);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
if (currentTimeMillis - lastTime > 60000) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong("lastTime", currentTimeMillis);
editor.apply();
Log.d("AAA","showAds");
}
}
}
AndroidManifest.xml
<?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.indiapps.documentscanner">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:requestLegacyExternalStorage="true"
android:name="com.MainApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admod_app_id"/>
<!-- HUNGDH -->
<activity
android:name="com.indiapps.documentscanner.camscanner.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:noHistory="true" />
<activity
android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:noHistory="true" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
<activity
android:name="com.indiapps.documentscanner.camscanner.MyPDFActivity"
android:label="#string/my_pdf"
android:theme="#style/AppTheme" />
<activity
android:name="com.indiapps.documentscanner.camscanner.FilterImageActivity"
android:label="#string/filter_image"
android:theme="#style/AppTheme" />
<activity
android:name="com.indiapps.documentscanner.camscanner.KnifeActivity"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.indiapps.documentscanner.camscanner.MySettingsActivity"
android:label="#string/action_settings"
android:theme="#style/AppTheme" />
<!-- DOCUMENT SCANNER -->
<activity
android:name="com.gpaddyv1.documentscanner.activities.SimpleDocumentScannerActivity"
android:label="#string/from_gallery"
android:theme="#style/AppTheme" />
<!-- IMAGE TO PDF -->
<activity
android:name="com.gun0912.tedpicker.ImagePickerActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme_picker" />
<!-- OPEN NOTE SCANNER -->
<activity
android:name=".OpenNoteScannerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_open_note_scanner"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".GalleryGridActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/my_gallery"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".FullScreenViewActivity"
android:theme="#style/FullscreenTheme" />
<activity
android:name=".SettingsActivity"
android:label="#string/settings"
android:theme="#style/AppTheme" />
<!-- PHOTO EDITOR -->
<activity android:name="com.gpaddyv1.documentscanner.process.view.ProcessImageActivity" />
<activity android:name="com.joshuabutton.queenscanner.sign.view.SignActivity" />
<activity android:name="com.joshuabutton.queenscanner.process.view.CombineBitMapActivity" />
<activity android:name="com.gpaddyv1.documentscanner.document.DocumentActivity" />
<activity android:name="com.joshuabutton.queenscanner.handle.HandleActivity" />
<activity android:name="com.indiapps.documentscanner.listdoc.DocsActivity" />
<activity
android:name=".AccountActivity"
android:theme="#style/AppTheme.NoActionBar1">
</activity>
</application>
</manifest>
You forgot to declare mIntersitialAd, you can do that right after the class opening braces.
public class Ads {
private InterstitialAd mInterstitialAd;
public static void showAds(Context context) {
//your code
}
}

Integrating Snap-kit in android

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>

android Implement chatting through push notification using parse.com api

I am doing a chat application . In the app i have to do chatting with help of push notifications using parse andorid sdk. I am successfull to generate push notications between different users . But not able to recieve push and add their data in list view . Here is code of maifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="example.chat.ChatApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity
android:name="example.chat.LoginActivity"
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>
<activity
android:name="example.chat.FriendslIst"
android:label="Friend list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.RegisterActivity"
android:label="#string/title_activity_register"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.FriendListActivity"
android:label="#string/title_activity_friend_list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.ChatActivity"
android:label="#string/title_activity_chat"
android:screenOrientation="portrait" >
</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="example.chat.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="example.chat.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
and code for my custom reciever
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, ""+intent, Toast.LENGTH_LONG).show();
}
}
and from java code I am sending push like this :
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereEqualTo("device_id", target);
ParsePush push = new ParsePush();
push.setQuery(query);
push.setMessage(message);
push.setExpirationTimeInterval(86400);
push.sendInBackground();
Please tell me where I am wrong for recieving data using reciever and what to do when i recive push means any logic or idea to move further . Thanks in advance
here is the manifiest file.....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your package name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="your package name.YourActivity"
android:label="#string/app_name" >
<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="your package name.YourCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="your package name.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
use this code to receive the push...
public class MyCustomReceiver extends BroadcastReceiver {
String title, from, msg;
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data")
: "";
Log.e("message ", " " + message);
JSONObject jObject;
try {
if (message != null && !message.equals("")) {
jObject = new JSONObject(message);
from = jObject.getString("from");
msg = jObject.getString("title");
title = jObject.getString("msg");
GCMMessage gcmMessage = new GCMMessage();
gcmMessage.setMsg_body(msg);
gcmMessage.setMsg_title(title);
gcmMessage.setType(0);
gcmMessage.setDateTime(time);
DatabaseUtil.insertMessage(context, gcmMessage);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
and here is the code to send push...
JSONObject obj;
try {
obj =new JSONObject();
obj.put("alert","oman expert ");
obj.put("action","Your Package name.UPDATE_STATUS");
data.put("from", ParseUser.getCurrentUser().getUsername());
obj.put("msg","hi");
obj.put("title","msg");
ParsePush push = new ParsePush();
ParseQuery query = ParseInstallation.getQuery();
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for any further query please let me know....
In the above code example, you have missed out few things,
Check your AndroidManifest.xml file, and add c2dm permissions,
permission android:name="your package.permission.C2D_MESSAGE" android:protectionLevel="signature"
uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"
uses-permission android:name="your package.permission.C2D_MESSAGE"
While sending the data, set the action in your data,
JSONObject data = new JSONObject();
try {
data.put("action", "your package.GOT_MESSAGE");
data.put("ya", ya);
data.put("from", ParseUser.getCurrentUser().getUsername());
}catch (Exception e){
e.printStackTrace();
return;
}
ParsePush parsePush = new ParsePush();
parsePush.setData(data);

Cannot get to launch the searchable activity

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".

blocking home button without root

http://www.kidzoneapp.com/uses.html
In this app, they somehow have an ability to protect users home button (after pressing there is no home dialog). I know that it is impossible, but how they did it?
Manifest, no word about launcher.
<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="3" android:versionName="1.2" package="com.deemo.kidzone.main"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS" />
<application android:label="#string/home_title" android:icon="#drawable/ic_launcher_home_48x48" android:persistent="true">
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="com.deemo.kidzone.main.Home" android:enabled="false" android:stateNotNeeded="true" android:excludeFromRecents="true" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation">
<meta-data android:name="android.dock_home" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="com.deemo.kidzone.main.Preferences" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="IncomingCallProtectionActivity" android:name=".IncomingCallProtectionActivity" android:excludeFromRecents="true" android:launchMode="singleTask" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="PreferencesProtectionActivity" android:name=".PreferencesProtectionActivity" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="ExitProtectionActivity" android:name=".ExitProtectionActivity" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="Fake" android:name=".Fake" />
<activity android:theme="#android:style/Widget.Holo.ScrollView" android:label="CheckingApplicationDialog" android:name=".CheckingApplicationDialog" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:name=".wizard.WelcomeWizardActivity" android:excludeFromRecents="true" android:screenOrientation="portrait">
<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:label="StepPasswordActivity" android:name=".wizard.StepPasswordActivity" android:excludeFromRecents="true" android:screenOrientation="portrait" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="StepAllowedApplicationsActivity" android:name=".wizard.StepAllowedApplicationsActivity" android:excludeFromRecents="true" android:screenOrientation="portrait" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="StepPhoneAvailabilityActivity" android:name=".wizard.StepPhoneAvailabilityActivity" android:excludeFromRecents="true" android:screenOrientation="portrait" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="StepLauncherActivity" android:name=".wizard.StepLauncherActivity" android:excludeFromRecents="true" android:screenOrientation="portrait" />
<activity android:label="StepActivity" android:name=".wizard.StepActivity" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="ChangePasswordActivity" android:name=".ChangePasswordActivity" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="ClearDefaultLauncherActivity" android:name=".wizard.ClearDefaultLauncherActivity" android:excludeFromRecents="true" android:screenOrientation="portrait" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="Exit" android:name=".Exit" android:excludeFromRecents="true" />
<activity android:theme="#android:style/Theme.NoTitleBar" android:label="AllowedApplicationList2" android:name=".AllowedApplicationList2" android:excludeFromRecents="true" />
<receiver android:name=".PhoneCallBroadcastReceiver" android:enabled="false">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver android:name=".OutgoingCallBroadcastReceiver" android:enabled="false">
<intent-filter android:priority="0">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<receiver android:name=".ApplicationBlockBroadcastReceiver" android:enabled="false">
<intent-filter android:priority="100">
<action android:name="com.deemo.kidzone.main.BLOCK" />
</intent-filter>
</receiver>
<service android:label="LogcatService" android:name=".LogcatService" />
<service android:label="LogcatService2" android:name=".LogcatService2" android:process=":remote" />
</application>
</manifest>
There is also some interesting lines in code
public static void disableHome(Context paramContext, PackageManager paramPackageManager)
{
paramPackageManager.setComponentEnabledSetting(new ComponentName(paramContext, "com.deemo.kidzone.main.Home"), 2, 0);
}
public static void enableHome(Context paramContext, PackageManager paramPackageManager)
{
paramPackageManager.setComponentEnabledSetting(new ComponentName(paramContext, "com.deemo.kidzone.main.Home"), 1, 1);
}
public void onItemClick(AdapterView paramAdapterView, View paramView, int paramInt, long paramLong)
{
ApplicationInfo localApplicationInfo = (ApplicationInfo)paramAdapterView.getItemAtPosition(paramInt);
if (TextUtils.equals(localApplicationInfo.title, Home.this.getString(2131099745)))
{
Intent localIntent = new Intent(Home.this, PreferencesProtectionActivity.class);
Home.this.startActivityForResult(localIntent, 17);
}
while (true)
{
return;
if (TextUtils.equals(localApplicationInfo.title, Home.this.getString(2131099746)))
{
Home.this.startActivityForResult(new Intent(Home.this, ExitProtectionActivity.class), 16);
continue;
}
Home.this.startActivity(localApplicationInfo.intent);
Home.lastRunningIntent = localApplicationInfo.intent;
Logcat.homeLaunched = false;
}
}
}
So how they blocked home button even without root, and how I can do that?
http://dl.dropbox.com/u/1928109/kzalvl12.apk
here is the app, I guess it won't work without market license.
Add the following to your activity and you can do the magic too. No rooted phone required :)
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}

Categories