Android Studio Bottom Navigation caused error - android-studio

I dont know how to solve it i try too much but if i make a bottom navigation my app unfortunately stopped working after splash screen plz help me
When i remove bottom navigation app works perfect but when i add bottom navigation it not works but i need to add bottom navigation How can i resolve this error
my xml code
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottom_nav"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_menu"
tools:layout_editor_absoluteX="1dp"
android:background="#color/white"
app:itemIconTint="#00695C"
app:itemTextColor="#00695C"
tools:layout_editor_absoluteY="49dp"
/>
My java file code
bottomNavigationView.findViewById(R.id.bottom_nav);
bottomNavigationView.setOnNavigationItemSelectedListener(onNav);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,new HomeFragment()).commit();
`private BottomNavigationView.OnNavigationItemSelectedListener onNav=new BottomNavigationView.OnNavigationItemSelectedListener()` {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
Fragment selected = null;
switch (item.getItemId()){
case R.id.nav_home:
selected = new HomeFragment();
break;
case R.id.nav_chat:
selected = new ChatFragment();
break;
case R.id.nav_discussion:
selected = new DiscussionFragment();
break;
case R.id.nav_notification:
selected = new NotificationFragment();
break;
case R.id.nav_profile:
selected = new ProfileFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, selected).commit();
return true;
}
};
MENU
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/nav_home"
android:title="#string/home"
app:showAsAction="always"
android:icon="#drawable/ic_home"
/>
<item android:id="#+id/nav_chat"
android:title="#string/chat"
app:showAsAction="always"
android:icon="#drawable/ic_inbox"/>
<item
android:id="#+id/nav_discussion"
android:title="Discussion"
app:showAsAction="always"
android:icon="#drawable/ic_discussion"/>
<item
android:id="#+id/nav_notification"
android:title="#string/notification"
app:showAsAction="always"
android:icon="#drawable/ic_notification"/>
<item
android:id="#+id/nav_profile"
android:title="#string/profile"
app:showAsAction="always"
android:icon="#drawable/ic_profile"/>
</menu>
Error Shown in logcat
07-05 01:24:26.822 5495-5514/com.example.appname E/ActivityThread: Failed to find provider
info for com.google.android.gms.chimera
07-05 01:24:26.823 5495-5514/com.example.appname E/DynamiteModule: Failed to load IDynamiteLoader from GmsCore: Application package com.google.android.gms not found
07-05 01:24:26.830 5495-5514/com.example.appname E/DynamiteModule: Failed to load IDynamiteLoader from GmsCore: Application package com.google.android.gms not found
07-05 01:24:27.591 5495-5515/com.example.appname E/ActivityThread: Failed to find provider info for com.google.android.gms.phenotype
07-05 01:24:32.340 5495-5495/com.example.appname E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.appname, PID: 5495
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paragonssoft.community/com.paragonssoft.community.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.google.android.material.bottomnavigation.BottomNavigationView.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.google.android.material.bottomnavigation.BottomNavigationView.findViewById(int)' on a null object reference
at com.example.appname.MainActivity.onCreate(MainActivity.java:35)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Related

How to get rid of "Unable to find explicit activity class" error even after declaring the activity in AndroidManifest.xml file?

I tried navigating from Main activity to the "second activity", but as soon as it switches the app gets crashed. Please note that I have included the new activity in AndroidManifests.xml
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.example.textme">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.TextMe"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
</application>
</manifest>
Why does it still show error?
com.example.textme E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.textme, PID: 22401
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.textme/java.lang.String}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2256)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1914)
at android.app.Activity.startActivityForResult(Activity.java:5326)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:705)
at android.app.Activity.startActivityForResult(Activity.java:5284)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:686)
at android.app.Activity.startActivity(Activity.java:5670)
at android.app.Activity.startActivity(Activity.java:5623)
at com.example.textme.MainActivity.onCreate$lambda-1(MainActivity.kt:25)
at com.example.textme.MainActivity.$r8$lambda$maNhvr12gpIoBBKbBDtjW2g9MFQ(Unknown Source:0)
at com.example.textme.MainActivity$$ExternalSyntheticLambda1.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7520)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194)
at android.view.View.performClickInternal(View.java:7489)
at android.view.View.access$3600(View.java:826)
at android.view.View$PerformClick.run(View.java:28555)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:245)
at android.app.ActivityThread.main(ActivityThread.java:8024)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Intent(Context packageContext, Class<?> cls)'s second argument should be Class<?>.
Unfortunately, when you provide java.lang.String as argument, compiler will not complain about it.
"SecondActivity"::class.java is java.lang.String
However, Android System will try to create an activity instance from java.lang.String which you did not declare in your AndroidManifest.xml.
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.textme/java.lang.String};
have you declared this activity in your AndroidManifest.xml?
When you put quotes arrond SecondActivity you make it just a string.
Please, see the correction below.
val next: Button = findViewById(R.id.next)
next.setOnClickListener {
// this provides String for second argument
// val intent = Intent(this, "SecondActivity"::class.java)
// correct call for activity start
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
}
Please note that I have included the new activity in AndroidManifests.xml
This kind of little errors happen all the time. First thing I do is read the error messages carefully.
Hope it helps.

Fatal Exception null object reference in Android studio

I'm working on an app where on a button click, the app will take the user from main activity to new activity. I've got everything coded and I am just trying to link up the activities now but I'm getting fatal errors which I cannot really understand. The app crashes when I try the button in testing and in Debug I get the error which I have pasted below. I've also pasted my code for the button and the XML for main activity. Can anybody help me make some sense of this error please? Also, if I have left any information out please let me know. Thanks.
Note: In the code for my button, the button I get the error with is the newactivity one.
Error:
2021-06-15 21:15:39.489 8340-8340/com.project.playshow E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.playshow, PID: 8340
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.playshow/com.fproject.playshow.newactivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.project.playshow.newctivity.onCreate(newactivity.kt:97)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7656) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
Code used in MainActivity for Button (newactivityopen is the one I'm having issues with)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var dialogbutton = findViewById<Button>(R.id.dialogbtn)
dialogbutton.setOnClickListener{
openDialogue()
}
var newactivityopen = findViewById<Button>(R.id.button_newactivity)
newactivityopen.setOnClickListener{
var intent = Intent(this, newactivity::class.java)
startActivity(intent);
}
}
XML File
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/dialogbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"/>
<Button
android:id="#+id/button_newactivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="569dp"
android:text="NewActivity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I´m not familiar with Kotlin (only java), but is it possible that you have setted the onClickListener to a Button, which doesn´t exist?
Try replacing these code snippets:
sdkButton.setOnClickListener with dialogbutton.setOnClickListener
button_newactivity.setOnClickListener with newactivityopen.setOnClickListener

XPAges: "java.io.NotSerializableException: lotus.domino.local.Document"

I have an XPage which holds one Notes document. The intention of this page is just to show some relevant fields of the document.
Accessing the page first time is ok. And also when showing later again without changing the underlaying document is ok.
But when I navigate from this to another XPage, and change the document there (yes, I have another page dedicated to edit the document), and then come back to the "show" page, I get the java.io.NotSerializableException in the render Response Phase.
Strange: it is for a lotus.domino.local.Document ... I never want to save/serialize a document ... :-o
What I've done to find the bug in my code:
I logged the viewScope content in beforeRenderResponse Event of the page, but there are only simple objects (strings and booleans).
I set the viewState of the page to "nostate".
I set the readonly attribute of the page to "true".
I removed every "on page loading" data-bindings (switched '${...}' to '#{...}')
So what else can I do to find the point of code, where some kind of document want to be saved?
What are typical error causes in this case?
Thanks for any help to help myself! :-)
My Stacktrace:
23.11.16 10:30: Exception Thrown
Context Path: /.../.../myApp.nsf
Page Name: /page_ShowData.xsp
com.ibm.xsp.FacesExceptionEx: java.io.NotSerializableException: lotus.domino.local.Document
at com.ibm.xsp.application.AbstractStateManager.saveSerializedView(AbstractStateManager.java:121)
at com.ibm.xsp.application.StateManagerImpl.saveSerializedView(StateManagerImpl.java:152)
at com.ibm.xsp.application.ViewHandlerExImpl._saveViewState(ViewHandlerExImpl.java:455)
at com.ibm.xsp.application.ViewHandlerExImpl.saveViewState(ViewHandlerExImpl.java:449)
at com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:324)
at com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:336)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)
at com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:270)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:261)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:588)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:865)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:808)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:577)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: java.io.NotSerializableException: lotus.domino.local.Document
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1185)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.ArrayList.writeObject(ArrayList.java:728)
at sun.reflect.GeneratedMethodAccessor652.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1059)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1502)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1433)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.HashMap.writeObject(HashMap.java:942)
at sun.reflect.GeneratedMethodAccessor637.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1059)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1502)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1433)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1179)
at java.io.ObjectOutputStream.writeUnshared(ObjectOutputStream.java:413)
at com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectOutputStream.writeObjectEx(AbstractSerializingStateManager.java:438)
at com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectOutputStream.writeObjectEx(AbstractSerializingStateManager.java:417)
at com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectOutputStream.writeObjectEx(AbstractSerializingStateManager.java:417)
at com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectOutputStream.writeObjectEx(AbstractSerializingStateManager.java:417)
at com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectOutputStream.writeObjectEx(AbstractSerializingStateManager.java:417)
at com.ibm.xsp.application.AbstractSerializingStateManager.saveSerializedView(AbstractSerializingStateManager.java:294)
at com.ibm.xsp.application.AbstractSerializingStateManager.doSaveSerializedView(AbstractSerializingStateManager.java:269)
at com.ibm.xsp.application.FileStateManager.doSaveSerializedView(FileStateManager.java:290)
at com.ibm.xsp.application.FileStateManager.doSaveSerializedView(FileStateManager.java:270)
at com.ibm.xsp.application.AbstractStateManager.saveSerializedView(AbstractStateManager.java:114)
... 25 more
My page_ShowData.xsp:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" pageTitle="Show Data"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex" readonly="true"
viewState="nostate"
afterPageLoad="#{javascript:print('page_ShowData.afterPageLoad()');}">
<!-- ... -->
<xp:this.data>
<xp:dominoDocument var="stamm" formName="Masterdata" ignoreRequestParams="false">
<xp:this.action>
<![CDATA[#{javascript:
// ensure to set the unid if known
if (viewScope.stammid == null){
viewScope.stammid = param.get('documentId');
}
if(typeof viewScope.stammid == "undefined" || viewScope.stammid == null || viewScope.stammid == ""){
return; // empty means 'create'
} else {
return 'openDocument';
}
}]]>
</xp:this.action>
<xp:this.documentId>
<![CDATA[#{javascript:return viewScope.stammid;}]]>
</xp:this.documentId>
<xp:this.postOpenDocument>
<![CDATA[#{javascript:
<!-- set some viewScope vars -->
}]]>
</xp:this.postOpenDocument>
<xp:this.postNewDocument>
<![CDATA[#{javascript:
<!-- set some viewScope vars -->
}]]>
</xp:this.postNewDocument>
</xp:dominoDocument>
</xp:this.data>
<!-- ... -->
<xp:this.beforeRenderResponse>
<![CDATA[#{javascript:
try{
// print all viewScope vars
var vsKeys:java.util.Set = viewScope.keySet();
for (var k in vsKeys){
var v = viewScope.get(k);
print('viewScope - ['+k.toString()+'] (serializable='+(k instanceof java.io.Serializable)+') = ['+v+'] (instance='+(typeof v)+', serializable='+(v instanceof java.io.Serializable)+')');
}
}]]>
</xp:this.beforeRenderResponse>
<!-- some UI content -->
</xp:view>
On one of those two XPages you're storing a NotesDocument (not DominoDocument datasource, but a NotesDocument object) in a scoped variable. Domino objects aren't serializable, which is what's throwing the error. The most likely place is the page you're moving from.
If you need access to a specific document, store the UNID of the document in the scoped variable and use database.getDocumentByUNID() to retrieve it. That's almost certainly what the DominoDocument datasource does.

Android Plugin for unity not opening permission dialogue in unity?

I just develop android plugin for unity and i am successfully able to exchange data between unity and android plugin.
in my android plugin my code is
String SCOPE = "https://www.googleapis.com/auth/youtube";
am.getAuthToken(myAccount_[0], "oauth2:" + SCOPE, null, this,
new OnTokenAcquired(), null);
It should prompt me to allow my app to access youtube.
Its working fine for my android application but not be able to ask on unity.
here is my code of android:
public void YoutubeSubscriber() {
AccountManager am = AccountManager.get(context);
Account[] myAccount_ = AccountManager.get(context).getAccountsByType("com.google");
Log.d("==============>all", String.valueOf(myAccount_));
Log.d("==============>single", String.valueOf(myAccount_[0]));
String SCOPE = "https://www.googleapis.com/auth/youtube";
am.getAuthToken(myAccount_[0], "oauth2:" + SCOPE, null, null,
new OnTokenAcquired(), null);
Toast.makeText(this.context, myAccount_[0].toString(), Toast.LENGTH_SHORT).show();
}
and using this in unity is like that.
using (AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
info.text = "activity";
activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
}
using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.thegamecontriver.androidlib.ToastExample"))
{
if (pluginClass != null)
{
toastExample = pluginClass.CallStatic<AndroidJavaObject>("instance");
toastExample.Call("setContext", activityContext);
info.text = "After ";
toastExample.Call("YoutubeSubscriber");
/*
activityContext.Call("runOnUiThread", new AndroidJavaRunnable(() => {
toastExample.Call("YoutubeSubscriber");
}));
*/
}
}
Note: i am able to see toast but permission is not prompting. please help
You are likely missing the permission required (USE_CREDENTIALS) to use AccountManager.
From getAuthToken SDK reference:
NOTE: If targeting your app to work on API level 22 and before,
USE_CREDENTIALS permission is needed for those platforms. See docs for
this function in API level 22.
1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android
2.Now open the copied Manifest file from <ProjectName>Assets\Plugins\Android and add <uses-permission android:name="android.permission.USE_CREDENTIALS"/> to it. Save, Build and Run. If this is a permission problem, that should now be solved.
What your AndroidManifest.xml should look like(Unity 5.4):
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
</manifest>

Eclipse Android error when switching to GUI xml

I get the following error when I switch from xml to GUI for a preferences layout file:
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- PreferenceCategory (Fix Build Path, Edit XML)
- PreferenceScreen (Fix Build Path, Edit XML)
My xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<PreferenceCategory
android:title="Activation">
<CheckBoxPreference
android:title="Title1"
android:defaultValue="false"
android:key="checkbox1">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory
android:title="Option1">
<PreferenceScreen
android:title="Set Option">
<CheckBoxPreference
android:title="ENABLE OPTION"
android:defaultValue="false"
android:summary="text"
android:key="checkboxOption1">
</CheckBoxPreference>
<CheckBoxPreference
android:title="DISPLAY OPTIONS"
android:defaultValue="false"
android:summary="text"
android:key="checkboxDisplay1">
</CheckBoxPreference>
<EditTextPreference
android:title="OPTION2"
android:name="Option2"
android:summary="text"
android:defaultValue="1"
android:key="editOption2">
</EditTextPreference>
<CheckBoxPreference
android:title="OPTION3"
android:defaultValue="false"
android:summary="text"
android:key="checkboxOption3">
</CheckBoxPreference>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory
android:title="Option4">
<PreferenceScreen
android:title="Set Option4">
<CheckBoxPreference
android:title="OPTION4"
android:defaultValue="false"
android:summary=""
android:key="checkboxOption4">
</CheckBoxPreference>
<CheckBoxPreference
android:title="OPTION5"
android:defaultValue="false"
android:summary="text"
android:key="checkboxOption5">
</CheckBoxPreference>
<EditTextPreference
android:title="OPTION6"
android:name="Option6"
android:summary="text"
android:defaultValue="1"
android:key="editOption6">
</EditTextPreference>
<EditTextPreference
android:title="OPTION7"
android:name="Option7"
android:summary="text"
android:defaultValue="1"
android:key="editOption7">
</EditTextPreference>
<EditTextPreference
android:title="OPTION8"
android:name="Option8"
android:summary="text"
android:defaultValue="1"
android:key="editOption8">
</EditTextPreference>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory
android:title="OPTION9">
<PreferenceScreen
android:title="Option9">
<EditTextPreference
android:title="Option9"
android:name="Option9"
android:summary="text"
android:defaultValue=""
android:key="editOption9">
</EditTextPreference>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
Any assistance would be greatly appreciated
I had this problem because I treated the preference list like a normal activity. It's actually completely different. First, you need to move the XML file from res/layout to res/xml (in Eclipse, you have to create this folder manually). You also have to use different Java code:
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Settings extends PreferenceActivity { //NOT activity!
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize the preference screen defined in /res/xml/preference.xml
addPreferencesFromResource(R.xml.preferences); //NOT setContentView
}
}
You'll get a warning for API level >=11 about addPreferencesFromResource being deprecated. That's because Android wants you to switch to a preference screen based on fragments ("PreferenceFragments"), which is a fair bit more complicated. There's an example here.

Resources