I have two apps one is android java app and other is unity app
Unity app recognize the object and shows some details. What i want to do is if user clicks the button which is shown when the object is identified, i want to send that information to the java android app so that the app can use that data to perform certain functions. How can i send the data and switch from unity to java android app after user clicks the button?
EDIT: For any one looking for the answer. I manage to do it by the code below
IN UNITY APP:
public void LaunchAppMessage()
{
string bundleId = "com.example.sidenavtest";
bool fail = false;
string message = "message";
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
launchIntent.Call<AndroidJavaObject>("putExtra", "arguments", message);
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{
Application.OpenURL("https://google.com");
}
else
{
ca.Call("startActivity", launchIntent);
}
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
}
IN ANDROID APP
#Override
protected void onStart() {
super.onStart();
Bundle extras = getIntent().getExtras();
String userName;
if (extras != null) {
userName = extras.getString("arguments");
}
}
If i understand you correctly you want to have both applications on the same device.
Simplest way would be to save the data ino a file in the unity application and read from that file in the android application. But i think you can even attach data on application calls so that you dont even need to save it temporarily.
Opening the Android app from Unity is possible aswell. Here someone asked the same question and got some working answer.
Edit: From what i can gather you can transfer your data via intents, it seem's like most people work with JAR-Plugin from where you can make a intent call.
Related
I want to know if it is possible to open my s health application (of my android smartphone), from another my application (android) that I'm building now.
But I want besides open the app, also set some data to this app, for example I want to set the aims, or any data. It is possible to do this?
It is possible to do this?
Yes!!
If you know the package name of the other app, here is an example which is tested and working!!!!!
(This demonstrates how to send a simple String value,modify params as you want )
openApp(yourActivity.this,"other.app.package.name","Hey I am coming catch me");
`
public static boolean openApp(Context context, String packageName,String dataNeedToPass) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//pkg Name Not Found
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.putExtra("KEY", dataNeedToPass);
context.startActivity(i);
return true;
} catch (Exception e) {
return false;
}
}
and in the launcher activity of the other side/app get the bundle
Bundle bundle = getIntent().getExtras();
if(bundle !=null){
String myString = bundle.getString("KEY");
}
p.s : If you want to send data make sure also the other app is modified and ready to catch!
My app is using a NotificationListener to read out messages from various 3rd party apps, for example WhatsApp.
So far I was able to send a reply if only one chat is unread, the code is below.
However, in the case with WhatsApp, getNotification().actions returns a null object when more than two chats are unread, as the messages are bundled together. As you can see in the pictures below, if the notifications are extended there is an option to send a direct reply as well, therefore I am certain that it is possible to utilize this, also I think apps like PushBullet are using this method.
How could I access the RemoteInput of that notification?
public static ReplyIntentSender sendReply(StatusBarNotification statusBarNotification, String name) {
Notification.Action actions[] = statusBarNotification.getNotification().actions;
for (Notification.Action act : actions) {
if (act != null && act.getRemoteInputs() != null) {
if (act.title.toString().contains(name)) {
if (act.getRemoteInputs() != null)
return new ReplyIntentSender(act);
}
}
}
return null;
}
public static class ReplyIntentSender {
[...]
public final Notification.Action action;
public ReplyIntentSender(Notification.Action extractedAction) {
action = extractedAction;
[...]
}
private boolean sendNativeIntent(Context context, String message) {
for (android.app.RemoteInput rem : action.getRemoteInputs()) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putCharSequence(rem.getResultKey(), message);
android.app.RemoteInput.addResultsToIntent(action.getRemoteInputs(), intent, bundle);
try {
action.actionIntent.send(context, 0, intent);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return false;
}
}
Some explanation how the above code works: Once a notification is received the app tries to get the actions and checks if the name is in the title of a remoteInput (normally it is in the format of "Reply to $NAME"), if that is found the Action is saved into a ReplyIntentSender class, which, when triggered by sendNativeIntent, cycles through all RemoteInputs of that Action and adds the message to the intent. If more than one chat is unread, getNotification().actions returns null.
Below are two screenshots, the first one where it is working without any problems and the second one where it doesn't.
You can consider this as my suggestion. I have done bit research on this and come up with following conclusions.(Also it looks like you have done plenty of research on this so it might be possible that you aware about what I wrote below)
Numerous apps send Wear specific notifications, and many of those contain actions accessible from an Android Wear device. We can grab those Wear notifications on the device, extracting the actions, finding the reply action (if one exists), populating it with our own response and then executing the PendingIntent which sends our response back the original app for it to send on to the recipient.
To do so you can refer this link (A nice workaround by Rob J). You can also refer this link in this context (Great research work done by Michał Tajchert).(You might need to work around with NotificationCompat.isGroupSummary)
This is what I feel(Might be I am totally wrong)
.actions method returns Array of all Notification.Action
structures attached to current notification by addAction(int,
CharSequence, PendingIntent), Here addAction method is deprecated
one so it might not working as intended.
I am not able to test this at my end otherwise I will love to provide a working solution with code.
Hope this will help you. Happy Coding!!!
second question, what is the WeChat app's package name? (due to i can't find it)
follow main quesition, i use WeChat official android sample code to execute the app.
But i don't know how to assign the specific WeChat user with sending out message .
any friend tell me how to finish it?
this is WeChat Sample code for sening message:
http://dev.wechat.com/download/sdk/WeChat_SDK_sample_android_en.zip
public static final String APP_ID = "wxd930ea5d5a258f4f";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
}
#Override
public void onClick(View v) {
WXTextObject textObj = new WXTextObject();
textObj.text = text;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.description = text;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("text");
req.message = msg;
req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
finish();
}
A.how can i know that i should send who?
B.APP_ID = "wxd930ea5d5a258f4f" represent is WeChat chat id?
C.i just run the sample app,then i send out message .it say"發送被拒絕"
that mean refuse to send message.what is the problem?
D.i live in Taiwan,When i register to http://dev.wechat.com/signup
. i input my Taiwan format phone code,but my phone never receive any
WeChat verification code for SMS
In result, i just want to know that how could the custom android app send message to the specific Wechat.Use the sample code to achieve the goal?
I am trying to get URL data when Unity3D android app is open from URL scheme. To get data which is come in URL I have written below in Unity3D :
using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
AndroidJavaObject context = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
String dataString = context.Call<AndroidJavaObject>("getIntent").Call<String>("getDataString");
Debug.LogError ("URL Data " +dataString );
I am able to get URL data but it always remain same if I am opening app from URL scheme or without URL scheme. So I guess the context is not updating when I am opening the app from background state.
Please provide me some suggestion to come out from this problem.
Add this code to Main Activity class
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
If I create an app that depends on another app or apps (eg: the Facebook and Twitter apps), yet they are not installed, is there a method of checking for those dependencies and installing them at the same time as my own app?
I did this in my application which requires the zxing scanner app to be installed.
You will want this inside your onclick or ontouch:
try{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, 0);
} catch (Exception e) {
createAlert("Barcode Scanner not installed!", "This application uses " +
"the open source barcode scanner by ZXing Team, you need to install " +
"this before you can use this software!", true);
}
which calls
public void createAlert(String title, String message, Boolean button) {
// http://androidideasblog.blogspot.com/2010/02/how-to-add-messagebox-in-android.html
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if ((button == true)) {
alertDialog.setButton("Download Now",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:com.google.zxing.client.android"));
startActivity(browserIntent);
}
});
}
alertDialog.show();
}
Then after sorting out all that code out I realise you asked for it to be installed at the same time as your app. Not sure if i should post this code, but it may be helpful
Short answer: No, you cannot automatically install other applications as dependencies.
Longer answer:
Android Market does not let you declare other applications to install as a dependency. As a system, Market appears to be designed for single application installs -- not Linux distro style mega dependency graphs.
At runtime, you can test for installed apps and punt your user over to the Market if so. See the techniques suggested by #QuickNick (testing if an app is installed) and #TerryProbert (punting to market) if that's what you want.
Your best bet is probably to design your app to gracefully degrade if dependencies are not available, and suggest (or insist) that they head over to market to install them.
Start from this:
Intent mediaIntent = new Intent("com.example.intent.action.NAME");
// add needed categories
List<ResolveInfo> listResolveInfo = getPackageManager().queryIntentServices(mediaIntent, 0);
if (listResolveInfo.size() != 0) {
//normal behavior
} else {
//install what you need
}
I give you example of querying services. If you want to check activities, then you will call queryIntentActivities().
I think following the pattern outlined in this post on the Android Developer Blog will help you.
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
As TerryProbert points out if you know that the Intent is not available prompt the user to install the missing app.
Here's what I use to return the first mission activity that exists:
try {
Class<?> missionClass = Class.forName(mPackageName+".Mission"+mission);
Method missionDescription;
missionDescription = missionClass.getMethod("missionDescription");
mMissionDescription = (String) missionDescription.invoke(null);
if (mMissionDescription.length() > 0) {
nextMission = mission;
break;
}
} catch (Exception e) {
//DEBUG*/Log.v(this.getClass().getName(), "onResume: Mission no "+mission+" not found: "+e.getMessage());
}
Each mission is held in a separate class, derived from a Mission base class. Derived classes are called Mission1, Mission24 etc.
Not all missions are defined.
The base class has an abstract class missionDescription which returns a string describing the mission.
This code is inside a loop so tests mission=1 to 99, trying to call missionDescription. It returns when the Description for the first mission found is returned.