******This is my Activity implementation in my Android manifest.xml******
<activity
android:name="com.zameen.zameenapp.GizmosActivity"
android:label="#string/title_gizmos" >
<intent-filter android:label="#string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”
<data android:scheme="example"
android:host="gizmos" />
-->
</intent-filter>
</activity>
This is my Activity Class
package com.zameen.zameenapp;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import android.app.Activity;
import android.content.Intent;
import android.drm.DrmStore.Action;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class GizmosActivity extends Activity
{
static final Uri APP_URI = Uri.parse("android-app://com.zameen.zameenapp/http/www.example.com/gizmos");
static final Uri WEB_URL = Uri.parse("http://www.example.com/gizmos/");
private GoogleApiClient mClient;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_side_menu);
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
#Override
public void onStart() {
super.onStart();
// Connect your client
mClient.connect();
// Define a title for your current page, shown in autocompletion UI
String title = "App Indexing API Title";
// Construct the Action performed by the user
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
// Call the App Indexing API start method after the view has completely rendered
AppIndex.AppIndexApi.start(mClient, viewAction);
}
#Override
public void onStop() {
// Call end() and disconnect the client
String title = "App Indexing API Title";
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
AppIndex.AppIndexApi.end(mClient, viewAction);
mClient.disconnect();
super.onStop();
}
}
I am implementing Google indexing in my App,i have already checked that on a specific Url that is www.example.com/gizmos i can easily start my activity using adb command line.
The problem is that i have to import Action Class Library files that is import com.google.android.gms.appindexing.Action;
But every time i try to add it i get errors and when import the prescribed library files as recommended by Eclipse i receive errors at AppIndex.AppIndexApi.end and also at newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI); I want to import library file for Action class in my GizmosActivity that could resolve the matter.also some one could tell me that my GizmosActivity code as well as manifest is well defined? and how can i test whether its working well
I would highly appreciate the solution
I finally got the Solution it was because of google Services Library was not updated,update the google Services using SDK and then import the Google services project from Sdk folder extras into your Eclipse and after that do not forget to add Google services lib in urs project libraries.
If you're using Android Studio, you can let Gradle handle this for you. Simply adding compile 'com.google.android.gms:play-services-appindexing:8.3.0' (or whatever version you desire) to your app's build.gradle (under dependencies) should let you import the App Indexing libraries you need.
Example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.google.android.gms:play-services-appindexing:8.3.0'
}
Reference
Related
I'm making an extension to update the operating system that there's a new image file, it gets called by a function in GM:S like this:
osNotice(files+"/newButtonSkin.png");
Note that the variable files is the absolout path
then the function sends this as a string to the java class extension:
package ${YYAndroidPackageName};//Import the GM:S stuff
import ${YYAndroidPackageName}.R;
import com.yoyogames.runner.RunnerJNILib;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.lang.String;
public class PickMe extends Activity {
public final void osNotice(String fupdate)//Notify the OS that there's a new media file available
{
Log.i("yoyo", "New file to alert os- "+fupdate);
String canAlert = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(canAlert))
{
File file = new File(fupdate);
Log.i("yoyo", "File ready to send- "+ fupdate);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file));
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
Log.i("yoyo", "Updated sucessfully! "+fupdate);
}
else
Log.i("yoyo", "Could not update file- "+fupdate);
}
}
in my manifest I have injected:
<activity android:name=".PickMe"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here's a screenshot of the log file when the game is run:
The result of running the app is that the image is not updated to the os, Why isn't the intent being run? and why does the log say "can't find method on extension class: null" when I know the method is being run?
Solved!! to make an intent visible to the Gamemaker: Studio side you have to call:
RunnerActivity.CurrentActivity.sendBroadcast(intent);
after finalizing building the intent.This tells the gm:s side that the broadcast intent to the Media Scanner has started. thanks to Mool over at the GMC comunity for pointing this out to me!!
And to elaborate more, broadcast intents are different from other intents that start an activity, broadcast intents fire an async event on the java side of the extension, if you are starting an activity within your java file you would alert the jnilib of gm:s with
RunnerActivity.CurrentActivity.startActivity(intent);
and also remembering to extend your class like:
public class MyClass extends Activity {// for either broadcast or start activity
I'm trying to build a splash screen for an Android RN app.
I've followed the steps described here : https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Unfortunately, when trying to launch my app, the build is successful but the app crashes saying:
Error type 3
Error: Activity class {com.needlios/com.needlios.MainActivity} does not exist.
Does any one know where this could come from ?
I have the following code :
SplashScreen.java
package com.needlios;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.java
package com.needlios;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "NeedlIOS";
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
#Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
);
}
}
AndroidManifest.xml
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
OK, well it works now. I just changed the android:name to android:name=".MainActivity" in AndroidManifest.xml
It works but I don't understand why it shows the splash screen though...
Just to share as I got this working too.
The change of the
android:name
to
android:name=".MainActivity" in AndroidManifest.xml
is working because the whole background has been modified to Splashscreen theme. It might not be a good solution, as if the backgroundColor is removed from any screens; this splash screen background will appear. Eventually it'll lead to some unwanted displays when you need to integrate with some camera features. :(
Most of the codes are based on this link with just splash activity removed. If anyone is searching do add values/colors.xml and drawable/backgroundsplash.xml.
You cant create splash screen inside ract-native script, you need go down to the native implementation.
To make simple splash screen, you need to set "android:windowBackground" on theme that used by you main activity. In such way them will be showed to user until your react-native view fully loaded.
Here is the article on how to do it.
Good morning - I hope everyone has had an enjoyable weekend.
I am having some issues following the tutorial at https://developer.chrome.com/multidevice/webview/gettingstarted
Everything is going well until I reach the step regarding an edit of the MainActivity class. This is Step 3 in the section Add the WebView: https://developer.chrome.com/multidevice/webview/gettingstarted#add_the_webview
Here is the content of my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nathan.myapplication" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
And here is my MyActivity.java:
package com.example.nathan.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class MyActivity extends Activity {
private WebView mWebView; // Added by ND Guthrie 8.15.2014:2229
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mWebView = (WebView)findViewById(R.id.activity_my_webview); // Added by ND Guthrie 8.15.2014:2231
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have tried suggestions based on these links here on stackoverflow:
Error with R class import in android
Android Studio don't generate R.java for my import project
R.id cannot be resolved
For the error with R class import, I have attempted adding the line
import com.TestApp.HelloWebView.R;
But with no success, as TestApp is not recognized. This stands to reason, since I have not named anything 'TestApp' in my app here, but I do not understand how to fix it.
I also tried deleting the generated folder and cleaning and rebuilding the project. However, I obtain the same results.
I know this is probably a silly little thing, but I have been searching google and stackoverflow for days now, and it seems like there is just something I am not seeing.
Any ideas? Please advise.
Thank you very much for your time!
Best,
Nathan
The way it works is that your XML files get compiled into resources in the background by Eclipse, and an R.java gets generated that allows your project to refer to these resources. If you put "R.id.blah" or "R.layout.blah" or whatever into Eclipse and it isn't recognised, it means one of the following:
Your XML files don't have corresponding elements. R.java is being created, but doesn't contain "R.id.blah" or whatever you're using, because your XML files don't contain elements that would compile with those IDs.
R.java couldn't be compiled at all. That'll be the case if there are errors in your project. You're best off making sure that there are no errors (no red crosses anywhere), and then seeing whether R.java appears. Once you've done that, you'll be able to find out what IDs are being generated, and that should point you in the direction of what's missing or inconsistent in your XML files.
I'm developing an app, that should support multiple android sdk versions. It uses the ActionBarSherlock library and sliding menu. On android 4.0+ the app runs just well. But when I try to run it on all of the devices with lower sdk version, the app crashes with strange error. Here is the stack trace:
08-08 11:54:11.626: ERROR/dalvikvm(4782): Could not find class 'ru.arsenalmedia.AvatatorActivity', referenced from method ru.arsenalmedia.Auth.complete
08-08 11:54:11.646: ERROR/dalvikvm(4782): Could not find class 'ru.arsenalmedia.AvatatorActivity', referenced from method ru.arsenalmedia.Auth.onActivityResult
08-08 11:54:11.696: ERROR/ResourceType(4782): Style contains key with bad entry: 0x010102ce
08-08 11:54:12.346: ERROR/dalvikvm(4782): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method ru.arsenalmedia.proto.Utils.enableStrictMode
08-08 11:54:18.346: ERROR/AndroidRuntime(4782): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: ru.arsenalmedia.AvatatorActivity
at ru.arsenalmedia.Auth.complete(Auth.java:119)
at ru.arsenalmedia.proto.ServiceWorker$ClientRequest$2.handleMessage(ServiceWorker.java:951)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Manifest:
<uses-sdk
android:minSdkVersion="8"
android:maxSdkVersion="17"
/>
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:name="ru.arsenalmedia.Avatator"
android:theme="#style/actionBarStyle"
>
<activity
android:screenOrientation="portrait"
android:name="ru.arsenalmedia.Auth"
android:label="#string/app_name"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name="ru.arsenalmedia.AvatatorActivity"
android:screenOrientation="portrait"
>
</activity>
<activity android:name="ru.arsenalmedia.SlidingPanelActivity" />
<activity android:name="ru.arsenalmedia.TestAct"/>
</application>
I thought, that it was because of the sliding menu. I've tried to use native SlidingPaneLayout, but the issue is the same. I read a lot about this and nothing really helps. Please, help !!!
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import ru.arsenalmedia.avatator.R;
import ru.arsenalmedia.proto.ContactInfo;
import ru.arsenalmedia.proto.GroupInfo;
import ru.arsenalmedia.proto.ServiceWorker;
public class AvatatorActivity extends SlidingFragmentActivity implements SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {
private static final String TAG = "AvatatorActivity";
protected Fragment mFragment;
private SearchView searchView;
private Menu menu;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
actionBarInit();
// set the Above View
if (savedInstanceState != null)
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, "mFragment");
if (mFragment == null)
mFragment = new GroupsList();
//searchView = (EditText) findViewById(R.layout.contact_search_edittext);
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, mFragment)
.commit();
// set the Behind View
setBehindContentView(R.layout.menu_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new AppMenuFragment())
.commit();
customizeSlidingMenu();
//updateMenuTitles();
invalidateOptionsMenu();
}
private void actionBarInit() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setSlidingActionBarEnabled(false);
}
private void customizeSlidingMenu() {
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setBackgroundResource(R.drawable.sliding_menu_selector);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "mFragment", mFragment);
}
public void switchContent(Fragment fragment) {
Log.d(TAG, "SWITCH CONTENT");
mFragment = fragment;
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
//updateMenuTitles();
invalidateOptionsMenu();
getSlidingMenu().showContent();
}
Are you using eclipse adt plugin? if so, just right click the project->properties->Java Build apth ->Order and export, then make the Android Dependencies is checked.
EDIT:
as you are using Intellij, have you checked if you have imported the SlidingMenu library as a module?
ps. , I am using Android studio & Maven, I think you can just import the project as library if you are not using maven.
StrictMode was introduced in API level 9 (version 2.3) so the older versions you're testing on must not be able to call it...
08-08 11:54:12.346: ERROR/dalvikvm(4782): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method ru.arsenalmedia.proto.Utils.enableStrictMode
When you call your Utils.enableStrictMode() method you should first check if the users device is running a version that has access to StrictMode.
EDIT:
Something like this may also be causing a problem; using xml attributes that didn't exist in older platforms in your styles.xml, per this line:
08-08 11:54:11.696: ERROR/ResourceType(4782): Style contains key with bad entry: 0x010102ce
It still doesn't explain your NoClassDefFoundError
This is a pretty elusive problem. You mentioned that it works on Android 4.0+, and that sets off an alarm that you might be using something that's not supported in older versions of Android.
But before all that, if you're using Eclipse, you should refresh your project and do a clean build. Sometimes Eclipse has trouble picking up AndroidManifest changes and you might be loading an older version on your emulator/device.
If it still fails, it might be that you're importing something not supported in older APIs, or perhaps the AvatatorActivity class extends something only available in newer APIs. Can you post some code for your AvatatorActivity (namely, the imports and what AvatatorActivity extends)?
It would also help to know what you set for android:minSdkVersion and android:targetSdkVersion.
======== EDIT ========
Thanks for posting the code. The SlidingFragmentActivity is very suspicious, and chances are this library is missing. The easiest way to debug this would be to save a copy of the current AvatatorActivity.java and replace it with the following to see if you can launch the activity.
public class AvatatorActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
}
}
If this bare-bone Activity launches, then there's a problem with your SlidingMenu setup.
Thanks everyone, I've found the solution. It was the problem with SearchView. You should use one from ActionBarSherlock or SupportLibrary
I was wondering what would happen if I wrote one code in XML and another in Java.
I had this code in my program:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
While in my Manifest I had this:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar">
</activity>
My application started with no issues but ran the Java code and not what I had in XML. I assume this is true for all XML edits but wanted to make sure, if I had a Java code that is similar to XML with a bit of differences, would it use my XML format or Java code?
It'll always use the Java code, since that's run second. If you're inflating from XML, though, and you inflate after doing some Java stuff (to the layout), then the XML overrides the code you wrote.
The code takes precedence over xml. You can always over-define things from the code you write. As #Cornholio pointed out if you manipulate xml-based configurations from java code it can modify things you have set from java code.
The Android framework however will never overwrite for example the xml layout files you created.