Android app unable to launch an activity after splash activity - java

My app is unable to move to the 2nd activity that's StartingPoint after successfully launching the splash activity. App closes saying "unfortunately theNewBoston has stopped working."
I am attaching the relevant files. hope someone can help me with this.
StartingPoint.java
package com.example.thenewboston;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class StartingPoint extends Activity {
int counter;
Button add,sub;
TextView display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
counter=0;
add=(Button)findViewById(R.id.addButton);
sub=(Button)findViewById(R.id.subButton);
display=(TextView) findViewById(R.id.display);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is = " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is = " + counter);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.starting_point, 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);
}
}
Splash.java
package com.example.thenewboston;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
#Override
public void onCreate(Bundle TV) {
// TODO Auto-generated method stub
super.onCreate(TV);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStatingPoint= new Intent("com.thenewboston.StartingPoint");
startActivity(openStatingPoint);
}
}
};
timer.start();
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thenewboston"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.thenewboston.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</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>
</application>
</manifest>

Try to change your code as below:
Intent openStatingPoint= new Intent(Splash.this,StartingPoint.class);
startActivity(openStatingPoint);
Explanation:
The constructor used here takes two parameters:
A Context as its first parameter (Splash.this is used because the Activity class is a subclass of Context)
The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started, here is StartingPoint.class)
See more Build an Intent

Thread class doesn't work on UI Thread so that instead of using Thread class use Handler class as follows -
Splash.java
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent openStatingPoint= new Intent(Splash.this,StartingPoint.class); // Use Explicit Intents
startActivity(openStatingPoint);
finish();
}
}, 5000); //time in milliseconds

check your logcat for the exception stack trace, it could be many reasons.
and

Related

How to receive ACTION_SCREEN_OFF with a "always running" service

I want to create an app that set/reset a timer to reproduce a song if the mobile spend 8 hours with the screen off.
I want to create a service that receive ACTION_SCREEN_OFF, but the problem is that when the app is killed from recent apps, the service is killed. I try with START_STICKY but the service is not restarted (onCreate is called sometimes but not onStart Command). I try to set in Manifest but the receiver must be register.
By now I only want that receiver detect ACTION_SCREEN_OFF.
I Have this code:
MainScreen.java (MainActivity)
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class MainScreen extends Activity implements View.OnClickListener{
public static final String MSG_TAG = "NoSleepMore";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
findViewById(R.id.start_service_button).setOnClickListener(this);
findViewById(R.id.stop_service_button).setOnClickListener(this);
}
#Override
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(), LockService.class);
switch (v.getId()) {
case R.id.start_service_button:
Log.e(MSG_TAG,"Service started");
//starts service for the given Intent
startService(intent);
break;
case R.id.stop_service_button:
Log.e(MSG_TAG,"Service stopped");
//stops service for the given Intent
stopService(intent);
break;
}
}
}
LockService.java
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class LockService extends Service {
#Override
public IBinder onBind(Intent arg0) {
Log.i(MainScreen.MSG_TAG, "onBind()" );
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(MainScreen.MSG_TAG, "Service Created");
/* Filtrar Acciones Capturadas */
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
// Listener
final BroadcastReceiver mReceiver = new ScreenReceiver();
// Registar Listener
registerReceiver(mReceiver, filter);
return Service.START_STICKY;
//return super.onStartCommand(intent, flags, startId);
}
#Override
public void onCreate() {
Log.i(MainScreen.MSG_TAG, "onCreate()");
}
#Override
public void onDestroy() {
Log.i(MainScreen.MSG_TAG, "onDestroy()");
}
}
ScreenRecive.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, final Intent intent) {
Log.i(MainScreen.MSG_TAG,"OnReceive->");
// Log Handel
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// do whatever you need to do here
Log.i(MainScreen.MSG_TAG,"Screen action OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// and do whatever you need to do here
Log.i(MainScreen.MSG_TAG,"Screen action ON");
}else if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
Log.e(MainScreen.MSG_TAG,"Action UserPresent");
}
}
}
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.mangel.nosleepmore">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
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=".MainScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SCREEN_ON"/>
<action android:name="android.intent.action.ACTION_SCREEN_OFF"/>
<action android:name="android.intent.action.ACTION_USER_PRESENT"/>
</intent-filter>
</receiver>
<service android:name=".LockService" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>
</application>
</manifest>
The Main activity is just two buttons.
BTW I just need that run over Android 8.0.

Deep linking opens the app but does not open the exact url

I have made a WebView app and deep linking works on it. Whenever someone clicks a link to my website (on any other app) then my app opens but, the homepage loads up instead of the URL clicked. I want the exact URL of my website to open whenever the link is clicked instead of the homepage.
MainActivity.java
package com.yoalfaaz.yoalfaaz;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.support.v4.view.MenuItemCompat;
public class MainActivity extends AppCompatActivity {
private WebView YoWeb;
private ShareActionProvider mShareActionProvider;
SwipeRefreshLayout swipe;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
YoWeb = (WebView)findViewById(R.id.webview); // Move your declaration up here
swipe = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
LoadWeb(YoWeb.getUrl()); // Pass in the current url to refresh
}
});
LoadWeb("https://www.yoalfaaz.com"); // load the home page only once
}
public void LoadWeb(String url) // Pass in URL you want to load
{
WebSettings webSettings = YoWeb.getSettings();
webSettings.setJavaScriptEnabled(true);
YoWeb.loadUrl(url); // Load the URL passed into the method
swipe.setRefreshing(true);
YoWeb.setWebViewClient(new WebViewClient() {
//onPageFinished Method
public void onPageFinished(WebView view, String url) {
//Hide the SwipeRefreshLayout
swipe.setRefreshing(false);
}
});
}
#Override
public void onBackPressed() {
if (YoWeb.canGoBack()) {
YoWeb.goBack();
} else {
super.onBackPressed();
}
}
#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.
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate menu resource file.
getMenuInflater().inflate(R.menu.menu_main, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
// Return true to display menu
return true;
}
// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
//private Intent setShareIntent() {
// Intent shareIntent = new Intent();
// shareIntent.setAction(Intent.ACTION_SEND);
// shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
// shareIntent.setType("text/plain");
// startActivity(shareIntent);
// return shareIntent;
//}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yoalfaaz.yoalfaaz">
<uses-permission android:name="android.permission.INTERNET" />
<application
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=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<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="www.yoalfaaz.com" android:scheme="https"/>
</intent-filter>
</activity>
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
How to make it work as it works with most other apps? Like if we click on a YouTube link in WhatsApp then that particular video opens in YouTube app instead of YouTube homepage.
LoadWeb("https://www.yoalfaaz.com"); // load the home page only once
Instead of hardcoding the URL, use getIntent().getData().toString() to get the URL(as a string) that is clicked from the other apps and use this URL to load web view.
Have a null check and load default URL if there is no URL received from getData().
Hope this helps.
========= EDITED to show the code as you have asked =====================
In your code, you are loading web view with this line.
LoadWeb("https://www.yoalfaaz.com"); // load the home page only once
Modify this line like below.
String url = "https://www.yoalfaaz.com";
if(null != getIntent().getData()){
url = getIntent().getData().toString();
}
LoadWeb(url);

My android app stops responding after the Splash Screen

I'm programming a new app which contains a splash screen.
I've finished it and it was all good. After I've opened android studio again to work on the navigation bar I've tried to run the app to see the result but the application stopped and crashed after the display of the splash screen.
this is Main class
package com.example.computer.bsinfoshop;
public class Main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
and this is the class od splash screen
package com.example.computer.bsinfoshop;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Screen extends AppCompatActivity {
TextView tv;
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
tv = (TextView)findViewById(R.id.textView);
img = (ImageView)findViewById(R.id.imageView);
Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf");
tv.setTypeface(font);
img.setImageResource(R.drawable.rsz_2rsz_img);
Thread timerThread = new Thread(){
public void run(){
try
{
sleep(3700);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally {
Intent intent = new Intent(Screen.this , Main.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
and here where i think is the problem
the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.computer.bsinfoshop">
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name">
<activity
android:name=".Screen"
android:theme="#style/App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"
android:label="Information"
android:theme="#style/AppTheme">
</activity>
<activity
android:name="com.example.computer.bsinfoshop.Main"
android:theme="#style/AppTheme">
</activity>
</application>
</manifest>
I just want to know what is the problem in my code and how can I fix it. thank you ^^
Change Thread to something like this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
finish();
startActivity(new Intent(Screen.this, Main.class));
}
}, 1500);
To be honest, I think this is not the correct way of creating a Splash Screen. That way you force the user to wait for 3 seconds which causes a bad user-experience.
Have a look at that tutorial and your users will thank you! https://www.bignerdranch.com/blog/splash-screens-the-right-way/

How to start service in dialer (default or stock dialer) of android

I want start a service when my dialer (default or stock dialer) open. My service just toasts a message. How to start the service for dialer. The startService command is working in MainActivity, but it is not working while a dialer is open.
My code is shown below:
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chatheads">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.DIAL_ACTION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" />
<activity android:name=".SecondActivity"></activity>
</application>
</manifest>
MainActivity.java
package com.example.chatheads;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.DialerKeyListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button startService,stopService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startService=(Button)findViewById(R.id.startService);
stopService=(Button)findViewById(R.id.stopService);
if(getIntent().getAction().equals(Intent.ACTION_DIAL)) {
Intent intent = new Intent(getBaseContext(), MyService.class);
startService(intent);
}
startService.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startService(new Intent(getApplication(), MyService.class));
}
});
stopService.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
stopService(new Intent(getApplication(), MyService.class));
}
});
}
}
Myservice.java
package com..service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
intent.getStringExtra("MY_MESSAGE");
//stopSelf();
return super.onStartCommand(intent, flags, startId);
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
This code is not working. The service starting when the startService calling in MainActivity. But when a dialer open it not working.
I think maybe you can try changing getApplication () to MainActivity.this.
And I think you need to jump from the dialer to MainActivity to get the service started

Where am I wrong with broadcasting info from Java and receiving in Unity?

So I just started working on this project and part of it is sending packages of information from an app in Java to another Unity app.
I have been trying to follow this tutorial but I have problems getting it to work and even somewhat understanding it a bit since I have not worked with Java before.
Here is the current code I have so far.
Main Activity Class
package com.example.service3;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
startService(new Intent(this, MyService.class));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Sender class
package com.example.service3;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
public class MyService extends Service
{
private final Handler handler = new Handler();
private int numIntent;
// It's the code we want our Handler to execute to send data
private Runnable sendData = new Runnable() {
// the specific method which will be executed by the handler
public void run() {
numIntent++;
// sendIntent is the object that will be broadcast outside our app
Intent sendIntent = new Intent();
// We add flags for example to work from background
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_FROM_BACKGROUND|Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
// SetAction uses a string which is an important name as it identifies the sender of the itent and that we will give to the receiver to know what to listen.
// By convention, it's suggested to use the current package name
sendIntent.setAction("com.example.service3");
// Here we fill the Intent with our data, here just a string with an incremented number in it.
sendIntent.putExtra(Intent.EXTRA_TEXT, "Intent "+numIntent);
// And here it goes ! our message is send to any other app that want to listen to it.
sendBroadcast(sendIntent);
// In our case we run this method each second with postDelayed
handler.removeCallbacks(this);
handler.postDelayed(this, 1000);
}
};
#Override
public void onStart(Intent intent, int startid) {
numIntent = 0;
// We first start the Handler
handler.removeCallbacks(sendData);
handler.postDelayed(sendData, 1000);
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
XML for Sender
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.service3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.service3.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="com.example.service3.MyService" />
</application>
Receiver Class
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Receiver extends BroadcastReceiver
{
private static Receiver instance;
public static String text ="1";
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
String sentIntent = intent.getStringExtra(Intent.EXTRA_TEXT);
text = "-1";
}
public static void createInstance()
{
if(instance == null)
{
instance = new Receiver();
}
}
}
Unity Android Manifest
<application android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false" android:isGame="true" android:banner="#drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<receiver android:name="com.example.receiver3.MyReceiver" >
<intent-filter>
<action android:name="com.example.receiver3" ></action>
</intent-filter>
</receiver>
</application>
I realise this is a massively large post but I simply do not know what to do at this point and am somewhat considering backing out of the project for the fact that I have no idea how to get Java to communicate with Unity.
Thanks in advance.

Categories