Gamemaker Studio android java extension not executing intent - java

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

Related

Home screen shortcut wont add

I am trying to add a short on home screen programmatically but it wont work.
The code works for Oreo and above but not below that.
public void addShortcutToHomeScreen() {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, "#1")
.setIntent(new Intent(this, ActivityMemes.class).setAction(Intent.ACTION_MAIN)) //!!! intent's action must be set on oreo
.setShortLabel("Memeify")
.setIcon(IconCompat.createWithResource(this, R.mipmap.ic_launcher))
.build();
ShortcutManagerCompat.requestPinShortcut(this, shortcutInfo, null);
} else {
Intent shortcutIntent = new Intent(getApplicationContext(),
Activity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(addIntent);
}
}
Here is my Manifest file.
<activity
android:name="com.my.package.Activities.Activity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Please, Tell me what am I doing wrong cause I have tried to fixed it and have failed. And is there any better way than this? Any help would be appreciated thanks.
EDIT :
Found this in the Logcat.
2019-01-16 13:27:46.773 735-13377/? W/BroadcastQueue: Permission Denial: broadcasting Intent { act=com.android.launcher.action.INSTALL_SHORTCUT flg=0x10 launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) } from com.chameleon.memeify (pid=14824, uid=10300) requires com.android.launcher.permission.INSTALL_SHORTCUT due to receiver com.sec.android.app.launcher/com.android.launcher3.home.InstallShortcutReceiver
you can use this method in your application class
public void createShortCut() {
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.logo);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashActivity.class));
sendBroadcast(shortcutintent);
}
}
and apply this permission
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
If your are on Android 8+ you can't use the broadcast anymore and you have to use the ShortcutManager :
https://developer.android.com/about/versions/oreo/android-8.0-changes#as
Android 8.0 (API level 26) includes the following changes to app shortcuts:
The com.android.launcher.action.INSTALL_SHORTCUT broadcast no longer has any effect on your app, because it is now a private, implicit broadcast. Instead, you should create an app shortcut by using the requestPinShortcut() method from the ShortcutManager class.
The ACTION_CREATE_SHORTCUT intent can now create app shortcuts that you manage using the ShortcutManager class. This intent can also create legacy launcher shortcuts that don't interact with ShortcutManager. Previously, this intent could create only legacy launcher shortcuts.
Shortcuts created using requestPinShortcut() and shortcuts created in an activity that handles the ACTION_CREATE_SHORTCUT intent are now fully-fledged app shortcuts. As a result, apps can now update them using the methods in ShortcutManager.
Legacy shortcuts retain their functionality from previous versions of Android, but you must convert them to app shortcuts manually in your app.
To learn more about changes to app shortcuts, see the Pinning Shortcuts and Widgets feature guide.

React Native Android Splash Screen

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.

implementing Google indexing in my App

******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

java.lang.NoClassDefFoundError: android

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

Launching Adobe Air app from my Android app

It it possible to start an adobe air apk from my current android app?
I tried this code but I got ActivityNotFoundException:
Intent intent = new Intent();
intent.setAction("air.caarsvcmobile.debug");
startActivity(intent);
Manifest:
<activity
android:name="caarsvcmobile"
android:label="CAARS Video Chat" >
<intent-filter>
<action android:name="air.caarsvcmobile.debug" />
</intent-filter>
</activity>
Is it possible to check package name and class name of an Air app?
After some Googling I found the solution of my problem:
Since I only knew the package name of the apk file I could use this code to launch the default launcher activity.
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("air.caarsvcmobile.debug");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Thats all. I works fine.

Categories